Skip to content

Commit

Permalink
Handle feedbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
nntthuy-axonivy committed Jul 5, 2024
1 parent 7a28140 commit 50bd1e3
Show file tree
Hide file tree
Showing 26 changed files with 169 additions and 162 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ private void createDetailResource(ProductDetailModel model, Product product) {
model.setCompatibility(product.getCompatibility());
model.setContactUs(product.getContactUs());
model.setCost(product.getCost());
model.setReadmeProductContents(product.getReadmeProductContents());
model.setProductModuleContents(product.getProductModuleContents());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
public class CommonConstants {
public static final int INITIAL_PAGE = 1;
public static final int INITIAL_PAGE_SIZE = 10;
public static final String SLASH = "/";
public static final String REQUESTED_BY = "X-Requested-By";
public static final String META_FILE = "meta.json";
public static final String LOGO_FILE = "logo.png";
public static final String DOT = ".";
public static final String SLASH = "/";
public static final String DOT_SEPARATOR = ".";
public static final String PLUS = "+";
public static final String DASH_SEPARATOR = "-";
public static final String SPACE_SEPARATOR = " ";
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ private MavenConstants() {
public static final String PRODUCT_ARTIFACT_POSTFIX = "-product";
public static final String METADATA_URL_FORMAT = "%s/%s/%s/maven-metadata.xml";
public static final String DEFAULT_IVY_MAVEN_BASE_URL = "https://maven.axonivy.com";
public static final String DOT_SEPARATOR = ".";
public static final String GROUP_ID_URL_SEPARATOR = "/";
public static final String ARTIFACT_ID_SEPARATOR = "-";
public static final String ARTIFACT_NAME_SEPARATOR = " ";
public static final String ARTIFACT_DOWNLOAD_URL_FORMAT = "%s/%s/%s/%s/%s-%s.%s";
public static final String ARTIFACT_NAME_FORMAT = "%s (%s)";
public static final String VERSION_EXTRACT_FORMAT_FROM_METADATA_FILE = "//versions/version/text()";
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/axonivy/market/constants/MetaConstants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.axonivy.market.constants;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class MetaConstants {
public static final String META_FILE = "meta.json";
public static final String DEFAULT_VENDOR_NAME = "Axon Ivy AG";
public static final String DEFAULT_VENDOR_URL = "https://www.axonivy.com";
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.axonivy.market.constants;

public class ProductJsonConstants {

public static final String PRODUCT_JSON_FILE = "product.json";
public static final String DATA = "data";
public static final String REPOSITORIES = "repositories";
public static final String URL = "url";
Expand All @@ -12,6 +12,7 @@ public class ProductJsonConstants {
public static final String TYPE = "type";
public static final String DEPENDENCIES = "dependencies";
public static final String INSTALLERS = "installers";
public static final String DEPENDENCY_SUFFIX = "-dependency";
public static final String MAVEN_IMPORT_INSTALLER_ID = "maven-import";
public static final String MAVEN_DROPIN_INSTALLER_ID = "maven-dropins";
public static final String MAVEN_DEPENDENCY_INSTALLER_ID = "maven-dependency";
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/axonivy/market/constants/ReadmeConstants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.axonivy.market.constants;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class ReadmeConstants {
public static final String IMAGES = "images";
public static final String README_FILE = "README.md";
public static final String DEMO_PART = "## Demo";
public static final String SETUP_PART = "## Setup";
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
@RestController
@RequestMapping(PRODUCT_DETAILS)
public class ProductDetailsController {
private final VersionService service;
private final VersionService versionService;
private final ProductService productService;
private final ProductDetailModelAssembler detailModelAssembler;

public ProductDetailsController(VersionService service, ProductService productService,
public ProductDetailsController(VersionService versionService, ProductService productService,
ProductDetailModelAssembler detailModelAssembler) {
this.service = service;
this.versionService = versionService;
this.productService = productService;
this.detailModelAssembler = detailModelAssembler;
}
Expand All @@ -43,7 +43,7 @@ public ResponseEntity<ProductDetailModel> findProductDetails(@PathVariable("id")
public ResponseEntity<List<MavenArtifactVersionModel>> findProductVersionsById(@PathVariable("id") String id,
@RequestParam(name = "isShowDevVersion") boolean isShowDevVersion,
@RequestParam(name = "designerVersion", required = false) String designerVersion) {
List<MavenArtifactVersionModel> models = service.getArtifactsAndVersionToDisplay(id, isShowDevVersion,
List<MavenArtifactVersionModel> models = versionService.getArtifactsAndVersionToDisplay(id, isShowDevVersion,
designerVersion);
return new ResponseEntity<>(models, HttpStatus.OK);
}
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/com/axonivy/market/entity/Product.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@
import java.util.Date;
import java.util.List;

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

import com.axonivy.market.github.model.MavenArtifact;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.springframework.data.annotation.Id;
Expand Down Expand Up @@ -46,7 +52,7 @@ public class Product implements Serializable {
private Integer installationCount;
private Date newestPublishedDate;
private String newestReleaseVersion;
private List<ReadmeProductContent> readmeProductContents;
private List<ProductModuleContent> productModuleContents;
private List<MavenArtifact> artifacts;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class ReadmeProductContent implements Serializable {
public class ProductModuleContent implements Serializable {
private static final long serialVersionUID = 1L;
private String tag;
private String description;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/axonivy/market/factory/ProductFactory.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.axonivy.market.factory;

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

import com.axonivy.market.github.util.GitHubUtils;
Expand Down Expand Up @@ -58,9 +58,9 @@ public static Product mappingByMetaJSONFile(Product product, GHContent ghContent
product.setTags(meta.getTags());
product.setVersion(meta.getVersion());
product.setShortDescription(meta.getDescription());
product.setVendor(StringUtils.isBlank(meta.getVendor()) ? "Axon Ivy AG" : meta.getVendor());
product.setVendor(StringUtils.isBlank(meta.getVendor()) ? DEFAULT_VENDOR_NAME : meta.getVendor());
product.setVendorUrl(
StringUtils.isBlank(meta.getVendorUrl()) ? "https://www.axonivy.com" : meta.getVendorUrl());
StringUtils.isBlank(meta.getVendorUrl()) ? DEFAULT_VENDOR_URL : meta.getVendorUrl());
product.setPlatformReview(meta.getPlatformReview());
product.setStatusBadgeUrl(meta.getStatusBadgeUrl());
product.setLanguage(meta.getLanguage());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.axonivy.market.github.service;

import com.axonivy.market.entity.ReadmeProductContent;
import com.axonivy.market.entity.ProductModuleContent;
import com.axonivy.market.github.model.MavenArtifact;

import org.kohsuke.github.GHContent;
Expand All @@ -16,7 +16,7 @@ public interface GHAxonIvyProductRepoService {

List<GHTag> getAllTagsFromRepoName(String repoName) throws IOException;

ReadmeProductContent getReadmeAndProductContentsFromTag(GHRepository ghRepository, String tag);
ProductModuleContent getReadmeAndProductContentsFromTag(GHRepository ghRepository, String tag);

List<MavenArtifact> convertProductJsonToMavenProductInfo(GHContent content) throws IOException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,17 @@
import java.io.IOException;
import java.util.*;

import com.axonivy.market.constants.CommonConstants;
import com.axonivy.market.constants.ReleaseTagConstants;
import com.axonivy.market.entity.ReadmeProductContent;
import com.axonivy.market.constants.*;
import com.axonivy.market.entity.ProductModuleContent;
import com.axonivy.market.github.util.GitHubUtils;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

import com.axonivy.market.constants.GitHubConstants;
import com.axonivy.market.github.service.GHAxonIvyProductRepoService;
import lombok.extern.log4j.Log4j2;

import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.util.Strings;
import com.axonivy.market.constants.ProductJsonConstants;
import com.axonivy.market.github.model.MavenArtifact;
import org.kohsuke.github.GHContent;
import org.kohsuke.github.GHOrganization;
Expand All @@ -42,6 +39,7 @@ public class GHAxonIvyProductRepoServiceImpl implements GHAxonIvyProductRepoServ
private String repoUrl;
private static final ObjectMapper objectMapper = new ObjectMapper();
public static final String DEMO_SETUP_TITLE = "(?i)## Demo|## Setup";
public static final String IMAGE_EXTENSION = "(.*?).(jpeg|jpg|png)";

private static final ObjectMapper MAPPER = new ObjectMapper();

Expand Down Expand Up @@ -143,53 +141,51 @@ public List<GHTag> getAllTagsFromRepoName(String repoName) throws IOException {
}

@Override
public ReadmeProductContent getReadmeAndProductContentsFromTag(GHRepository ghRepository, String tag) {
ReadmeProductContent readmeProductContent = new ReadmeProductContent();
public ProductModuleContent getReadmeAndProductContentsFromTag(GHRepository ghRepository, String tag) {
ProductModuleContent productModuleContent = new ProductModuleContent();
try {
List<GHContent> contents = getRepoContents(ghRepository, tag);
readmeProductContent.setTag(tag);
getProductJsonContent(readmeProductContent, contents);
List<GHContent> contents = getProductFolderContents(ghRepository, tag);
productModuleContent.setTag(tag);
getProductJsonContent(productModuleContent, contents);
GHContent readmeFile = contents.stream().filter(GHContent::isFile)
.filter(content -> ReleaseTagConstants.README_FILE.equals(content.getName())).findFirst()
.filter(content -> ReadmeConstants.README_FILE.equals(content.getName())).findFirst()
.orElse(null);
if (Objects.nonNull(readmeFile)) {
String readmeContents = new String(readmeFile.read().readAllBytes());
if (containsImageDirectives(readmeContents)) {
if (hasImageDirectives(readmeContents)) {
readmeContents = updateImagesWithDownloadUrl(contents, readmeContents);
getExtractedPartsOfReadme(readmeProductContent, readmeContents);
} else {
getExtractedPartsOfReadme(readmeProductContent, readmeContents);
}
getExtractedPartsOfReadme(productModuleContent, readmeContents);
}
} catch (Exception e) {
log.error("Cannot get product.json and README file's content {}", e);
return null;
}
return readmeProductContent;
return productModuleContent;
}

private void getProductJsonContent(ReadmeProductContent readmeProductContent, List<GHContent> contents)
private void getProductJsonContent(ProductModuleContent productModuleContent, List<GHContent> contents)
throws IOException {
String productJsonContents;
GHContent productJsonFile = contents.stream().filter(GHContent::isFile)
.filter(content -> ReleaseTagConstants.PRODUCT_JSON_FILE.equals(content.getName())).findFirst()
.filter(content -> ProductJsonConstants.PRODUCT_JSON_FILE.equals(content.getName())).findFirst()
.orElse(null);
if (Objects.nonNull(productJsonFile)) {
productJsonContents = new String(productJsonFile.read().readAllBytes());
JsonNode rootNode = MAPPER.readTree(productJsonContents);
JsonNode installersNode = rootNode.path(ReleaseTagConstants.INSTALLERS);
JsonNode installersNode = rootNode.path(ProductJsonConstants.INSTALLERS);
for (JsonNode installerNode : installersNode) {
if (installerNode.path(ReleaseTagConstants.ID).asText()
.endsWith(ReleaseTagConstants.DEPENDENCY_SUFFIX)) {
JsonNode dataNode = installerNode.path(ReleaseTagConstants.DATA);
JsonNode dependenciesNode = dataNode.path(ReleaseTagConstants.DEPENDENCIES);
readmeProductContent.setIsDependency(Boolean.TRUE);
readmeProductContent
.setGroupId(dependenciesNode.get(0).path(ReleaseTagConstants.GROUP_ID).asText());
readmeProductContent
.setArtifactId(dependenciesNode.get(0).path(ReleaseTagConstants.ARTIFACT_ID).asText());
readmeProductContent.setType(dependenciesNode.get(0).path(ReleaseTagConstants.TYPE).asText());
readmeProductContent.setName(GitHubUtils.convertArtifactIdToName(readmeProductContent.getArtifactId()));
if (installerNode.path(ProductJsonConstants.ID).asText()
.endsWith(ProductJsonConstants.DEPENDENCY_SUFFIX)) {
JsonNode dataNode = installerNode.path(ProductJsonConstants.DATA);
JsonNode dependenciesNode = dataNode.path(ProductJsonConstants.DEPENDENCIES);
productModuleContent.setIsDependency(Boolean.TRUE);
productModuleContent
.setGroupId(dependenciesNode.get(0).path(ProductJsonConstants.GROUP_ID).asText());
productModuleContent
.setArtifactId(dependenciesNode.get(0).path(ProductJsonConstants.ARTIFACT_ID).asText());
productModuleContent.setType(dependenciesNode.get(0).path(ProductJsonConstants.TYPE).asText());
productModuleContent.setName(GitHubUtils.convertArtifactIdToName(productModuleContent.getArtifactId()));
}
}
}
Expand All @@ -198,13 +194,13 @@ private void getProductJsonContent(ReadmeProductContent readmeProductContent, Li
public String updateImagesWithDownloadUrl(List<GHContent> contents, String readmeContents) throws IOException {
Map<String, String> imageUrls = new HashMap<>();
GHContent productImage = contents.stream().filter(GHContent::isFile)
.filter(content -> content.getName().toLowerCase().matches(".+\\.(jpeg|jpg|png)")).findAny()
.filter(content -> content.getName().toLowerCase().matches(IMAGE_EXTENSION)).findAny()
.orElse(null);
if (Objects.nonNull(productImage)) {
imageUrls.put(productImage.getName(), productImage.getDownloadUrl());
} else {
GHContent imageFolder = contents.stream().filter(GHContent::isDirectory)
.filter(content -> ReleaseTagConstants.IMAGES.equals(content.getName())).findFirst().orElse(null);
.filter(content -> ReadmeConstants.IMAGES.equals(content.getName())).findFirst().orElse(null);
if (Objects.nonNull(imageFolder)) {
for (GHContent imageContent : imageFolder.listDirectoryContent().toList()) {
imageUrls.put(imageContent.getName(), imageContent.getDownloadUrl());
Expand All @@ -221,10 +217,10 @@ public String updateImagesWithDownloadUrl(List<GHContent> contents, String readm

// Cover some cases including when demo and setup parts switch positions or
// missing one of them
public void getExtractedPartsOfReadme(ReadmeProductContent readmeProductContent, String readmeContents) {
public void getExtractedPartsOfReadme(ProductModuleContent productModuleContent, String readmeContents) {
String[] parts = readmeContents.split(DEMO_SETUP_TITLE);
boolean hasDemoPart = readmeContents.contains(ReleaseTagConstants.DEMO_PART);
boolean hasSetupPart = readmeContents.contains(ReleaseTagConstants.SETUP_PART);
boolean hasDemoPart = readmeContents.contains(ReadmeConstants.DEMO_PART);
boolean hasSetupPart = readmeContents.contains(ReadmeConstants.SETUP_PART);
String description = Strings.EMPTY;
String setup = Strings.EMPTY;
String demo = Strings.EMPTY;
Expand All @@ -247,19 +243,19 @@ public void getExtractedPartsOfReadme(ReadmeProductContent readmeProductContent,
setup = parts[1];
}

readmeProductContent.setDescription(description.trim());
readmeProductContent.setDemo(demo.trim());
readmeProductContent.setSetup(setup.trim());
productModuleContent.setDescription(description.trim());
productModuleContent.setDemo(demo.trim());
productModuleContent.setSetup(setup.trim());
}

private static boolean isDemoPlaceBeforeSetupPart(String readmeContents) {
return readmeContents.indexOf(ReleaseTagConstants.DEMO_PART) < readmeContents
.indexOf(ReleaseTagConstants.SETUP_PART);
return readmeContents.indexOf(ReadmeConstants.DEMO_PART) < readmeContents
.indexOf(ReadmeConstants.SETUP_PART);
}

private List<GHContent> getRepoContents(GHRepository ghRepository, String tag) throws IOException {
private List<GHContent> getProductFolderContents(GHRepository ghRepository, String tag) throws IOException {
return ghRepository.getDirectoryContent(CommonConstants.SLASH, tag).stream().filter(GHContent::isDirectory)
.filter(content -> content.getName().endsWith(ReleaseTagConstants.PRODUCT_FOLDER_SUFFIX))
.filter(content -> content.getName().endsWith(MavenConstants.PRODUCT_ARTIFACT_POSTFIX))
.flatMap(content -> {
try {
return content.listDirectoryContent().toList().stream();
Expand All @@ -269,8 +265,8 @@ private List<GHContent> getRepoContents(GHRepository ghRepository, String tag) t
}).toList();
}

private boolean containsImageDirectives(String readmeContents) {
Pattern pattern = Pattern.compile("(.*?).(jpeg|jpg|png)");
private boolean hasImageDirectives(String readmeContents) {
Pattern pattern = Pattern.compile(IMAGE_EXTENSION);
Matcher matcher = pattern.matcher(readmeContents);
return matcher.find();
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/axonivy/market/github/util/GitHubUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.util.List;
import java.util.stream.Collectors;

import com.axonivy.market.constants.MavenConstants;
import com.axonivy.market.constants.CommonConstants;
import org.apache.commons.lang3.StringUtils;
import org.kohsuke.github.GHCommit;
import org.kohsuke.github.GHContent;
Expand Down Expand Up @@ -55,8 +55,8 @@ public static String convertArtifactIdToName(String artifactId) {
if (StringUtils.isBlank(artifactId)) {
return StringUtils.EMPTY;
}
return Arrays.stream(artifactId.split(MavenConstants.ARTIFACT_ID_SEPARATOR))
return Arrays.stream(artifactId.split(CommonConstants.DASH_SEPARATOR))
.map(part -> part.substring(0, 1).toUpperCase() + part.substring(1).toLowerCase())
.collect(Collectors.joining(MavenConstants.ARTIFACT_NAME_SEPARATOR));
.collect(Collectors.joining(CommonConstants.SPACE_SEPARATOR));
}
}
Loading

0 comments on commit 50bd1e3

Please sign in to comment.