Skip to content

Commit

Permalink
Merge branch 'develop' into bugfix/MARP-692-Feedback-Anais-3-Adjustme…
Browse files Browse the repository at this point in the history
…nts-for-footer
  • Loading branch information
ntqdinh-axonivy committed Jul 19, 2024
2 parents f574f98 + 118e4ba commit b58934e
Show file tree
Hide file tree
Showing 20 changed files with 303 additions and 560 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class GitHubConstants {
public static final String PRODUCT_JSON_FILE_PATH_FORMAT = "%s/product.json";
public static final String GITHUB_PROVIDER_NAME = "GitHub";
public static final String GITHUB_GET_ACCESS_TOKEN_URL = "https://github.com/login/oauth/access_token";
public static final String README_FILE_LOCALE_REGEX = "_(..)";

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public static class Json {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
public class ReadmeConstants {
public static final String IMAGES = "images";
public static final String README_FILE = "README.md";
public static final String README_FILE_NAME = "README";
public static final String DEMO_PART = "## Demo";
public static final String SETUP_PART = "## Setup";
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
package com.axonivy.market.entity;

import static com.axonivy.market.constants.EntityConstants.PRODUCT;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;

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

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import static com.axonivy.market.constants.EntityConstants.PRODUCT;

@Getter
@Setter
Expand All @@ -31,10 +33,10 @@ public class Product implements Serializable {
private String id;
private String marketDirectory;
@JsonProperty
private MultilingualismValue names;
private Map<String, String> names;
private String version;
@JsonProperty
private MultilingualismValue shortDescriptions;
private Map<String, String> shortDescriptions;
private String logoUrl;
private Boolean listed;
private String type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import lombok.Setter;

import java.io.Serializable;
import java.util.Map;

@Getter
@Setter
Expand All @@ -14,7 +15,7 @@
public class ProductModuleContent implements Serializable {
private static final long serialVersionUID = 1L;
private String tag;
private String description;
private Map<String, String> description;
private String setup;
private String demo;
private Boolean isDependency;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
package com.axonivy.market.factory;

import static com.axonivy.market.constants.CommonConstants.LOGO_FILE;
import static com.axonivy.market.constants.CommonConstants.SLASH;
import static com.axonivy.market.constants.MetaConstants.DEFAULT_VENDOR_NAME;
import static com.axonivy.market.constants.MetaConstants.DEFAULT_VENDOR_URL;
import static com.axonivy.market.constants.MetaConstants.META_FILE;
import static org.apache.commons.lang3.StringUtils.EMPTY;

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

import org.apache.commons.lang3.BooleanUtils;
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;
import lombok.NoArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.kohsuke.github.GHContent;
import org.springframework.util.CollectionUtils;

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

import static com.axonivy.market.constants.CommonConstants.LOGO_FILE;
import static com.axonivy.market.constants.CommonConstants.SLASH;
import static com.axonivy.market.constants.MetaConstants.DEFAULT_VENDOR_NAME;
import static com.axonivy.market.constants.MetaConstants.DEFAULT_VENDOR_URL;
import static com.axonivy.market.constants.MetaConstants.META_FILE;
import static org.apache.commons.lang3.StringUtils.EMPTY;

@Log4j2
@NoArgsConstructor(access = AccessLevel.PRIVATE)
Expand Down Expand Up @@ -76,15 +78,11 @@ public static Product mappingByMetaJSONFile(Product product, GHContent ghContent
return product;
}

private static MultilingualismValue mappingMultilingualismValueByMetaJSONFile(List<DisplayValue> list) {
MultilingualismValue value = new MultilingualismValue();
private static Map<String, String> mappingMultilingualismValueByMetaJSONFile(List<DisplayValue> list) {
Map<String, String> value = new HashMap<>();
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());
}
value.put(name.getLocale(), name.getValue());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,4 @@ public GHRepository getRepository() {
return repository;
}

}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
package com.axonivy.market.github.service.impl;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.util.Strings;
import org.kohsuke.github.GHContent;
import org.kohsuke.github.GHOrganization;
import org.kohsuke.github.GHRepository;
import org.kohsuke.github.GHTag;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import com.axonivy.market.constants.CommonConstants;
import com.axonivy.market.constants.GitHubConstants;
import com.axonivy.market.constants.MavenConstants;
Expand All @@ -8,31 +27,15 @@
import com.axonivy.market.constants.ReadmeConstants;
import com.axonivy.market.entity.Product;
import com.axonivy.market.entity.ProductModuleContent;
import com.axonivy.market.enums.Language;
import com.axonivy.market.github.model.MavenArtifact;
import com.axonivy.market.github.service.GHAxonIvyProductRepoService;
import com.axonivy.market.github.service.GitHubService;
import com.axonivy.market.github.util.GitHubUtils;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.util.Strings;
import org.kohsuke.github.GHContent;
import org.kohsuke.github.GHOrganization;
import org.kohsuke.github.GHRepository;
import org.kohsuke.github.GHTag;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import lombok.extern.log4j.Log4j2;

@Log4j2
@Service
Expand Down Expand Up @@ -150,14 +153,17 @@ public ProductModuleContent getReadmeAndProductContentsFromTag(Product product,
List<GHContent> contents = getProductFolderContents(product, ghRepository, tag);
productModuleContent.setTag(tag);
getDependencyContentsFromProductJson(productModuleContent, contents);
GHContent readmeFile = contents.stream().filter(GHContent::isFile)
.filter(content -> ReadmeConstants.README_FILE.equals(content.getName())).findFirst().orElse(null);
if (Objects.nonNull(readmeFile)) {
String readmeContents = new String(readmeFile.read().readAllBytes());
if (hasImageDirectives(readmeContents)) {
readmeContents = updateImagesWithDownloadUrl(product, contents, readmeContents);
List<GHContent> readmeFiles = contents.stream().filter(GHContent::isFile)
.filter(content -> content.getName().startsWith(ReadmeConstants.README_FILE_NAME)).toList();
if (!CollectionUtils.isEmpty(readmeFiles)) {
for (GHContent readmeFile : readmeFiles) {
String readmeContents = new String(readmeFile.read().readAllBytes());
if (hasImageDirectives(readmeContents)) {
readmeContents = updateImagesWithDownloadUrl(product, contents, readmeContents);
}
String locale = getReadmeFileLocale(readmeFile.getName());
getExtractedPartsOfReadme(productModuleContent, readmeContents, locale);
}
getExtractedPartsOfReadme(productModuleContent, readmeContents);
}
} catch (Exception e) {
log.error("Cannot get product.json and README file's content {}", e);
Expand All @@ -166,6 +172,16 @@ public ProductModuleContent getReadmeAndProductContentsFromTag(Product product,
return productModuleContent;
}

private String getReadmeFileLocale(String readmeFile) {
String result = StringUtils.EMPTY;
Pattern pattern = Pattern.compile(GitHubConstants.README_FILE_LOCALE_REGEX);
Matcher matcher = pattern.matcher(readmeFile);
if (matcher.find()) {
result = matcher.group(1);
}
return result;
}

private void getDependencyContentsFromProductJson(ProductModuleContent productModuleContent, List<GHContent> contents)
throws IOException {
GHContent productJsonFile = getProductJsonFile(contents);
Expand Down Expand Up @@ -223,7 +239,8 @@ private void getImagesFromImageFolder(Product product, List<GHContent> contents,

// Cover some cases including when demo and setup parts switch positions or
// missing one of them
public void getExtractedPartsOfReadme(ProductModuleContent productModuleContent, String readmeContents) {
public void getExtractedPartsOfReadme(ProductModuleContent productModuleContent, String readmeContents,
String locale) {
String[] parts = readmeContents.split(DEMO_SETUP_TITLE);
int demoIndex = readmeContents.indexOf(ReadmeConstants.DEMO_PART);
int setupIndex = readmeContents.indexOf(ReadmeConstants.SETUP_PART);
Expand All @@ -249,11 +266,22 @@ public void getExtractedPartsOfReadme(ProductModuleContent productModuleContent,
setup = parts[1];
}

productModuleContent.setDescription(description.trim());
setDescriptionWithLocale(productModuleContent, description.trim(), locale);
productModuleContent.setDemo(demo.trim());
productModuleContent.setSetup(setup.trim());
}

private void setDescriptionWithLocale(ProductModuleContent productModuleContent, String description, String locale) {
if (productModuleContent.getDescription() == null) {
productModuleContent.setDescription(new HashMap<>());
}
if (StringUtils.isEmpty(locale)) {
productModuleContent.getDescription().put(Language.EN.getValue(), description);
} else {
productModuleContent.getDescription().put(locale.toLowerCase(), description);
}
}

private List<GHContent> getProductFolderContents(Product product, GHRepository ghRepository, String tag)
throws IOException {
String productFolderPath = ghRepository.getDirectoryContent(CommonConstants.SLASH, tag).stream()
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package com.axonivy.market.model;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.springframework.hateoas.RepresentationModel;
import org.springframework.hateoas.server.core.Relation;

import java.util.List;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;

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

@Getter
@Setter
Expand All @@ -19,8 +22,8 @@
@JsonInclude(Include.NON_NULL)
public class ProductModel extends RepresentationModel<ProductModel> {
private String id;
private MultilingualismValue names;
private MultilingualismValue shortDescriptions;
private Map<String, String> names;
private Map<String, String> shortDescriptions;
private String logoUrl;
private String type;
private List<String> tags;
Expand Down
Loading

0 comments on commit b58934e

Please sign in to comment.