Skip to content

Commit

Permalink
Merge branch 'develop' into feature/MARP-957-Add-URLs-for-LinkedIn-Xi…
Browse files Browse the repository at this point in the history
…ng-YouTube
  • Loading branch information
vhhoang-axonivy committed Aug 27, 2024
2 parents 611d4d6 + 7e75e29 commit e115999
Show file tree
Hide file tree
Showing 26 changed files with 433 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
public class WebConfig implements WebMvcConfigurer {

private static final String ALL_MAPPINGS = "/**";
private static final String[] EXCLUDE_PATHS = { "/", "/swagger-ui/**", "/api-docs/**" };
private static final String[] EXCLUDE_PATHS = { "/", "/swagger-ui/**", "/api-docs/**",
"/api/product-details/productjsoncontent/**" , };
private static final String[] ALLOWED_HEADERS = { "Accept-Language", "Content-Type", "Authorization",
"X-Requested-By", "x-requested-with", "X-Forwarded-Host", "x-xsrf-token", "x-authorization" };
private static final String[] ALLOWED_METHODS = { "GET", "POST", "PUT", "DELETE", "OPTIONS" };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ public class EntityConstants {
public static final String GH_REPO_META = "GitHubRepoMeta";
public static final String FEEDBACK = "Feedback";
public static final String PRODUCT_CUSTOM_SORT = "ProductCustomSort";
public static final String PRODUCT_JSON_CONTENT = "ProductJsonContent";
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ public class ProductJsonConstants {
public static final String INSTALLERS = "installers";
public static final String MAVEN_IMPORT_INSTALLER_ID = "maven-import";
public static final String MAVEN_DROPINS_INSTALLER_ID = "maven-dropins";
public static final String VERSION_VALUE = "${version}";
public static final String MAVEN_DEPENDENCY_INSTALLER_ID = "maven-dependency";
public static final String CUSTOM_ORDER = "customOrder";
public static final String EN_LANGUAGE = "en";
public static final String NAME = "name";

private ProductJsonConstants() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@ public class RequestMappingConstants {
public static final String PRODUCT_BY_ID = "/product/{id}";
public static final String PRODUCT_RATING_BY_ID = "/product/{id}/rating";
public static final String INSTALLATION_COUNT_BY_ID = "/installationcount/{id}";
public static final String PRODUCT_JSON_CONTENT_BY_PRODUCT_ID_AND_VERSION = "/productjsoncontent/{productId}/{version}";
public static final String VERSIONS_IN_DESIGNER = "/{id}/designerversions";
public static final String CUSTOM_SORT = "custom-sort";
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ public class RequestParamConstants {
public static final String SHOW_DEV_VERSION = "isShowDevVersion";
public static final String DESIGNER_VERSION = "designerVersion";
public static final String VERSION = "version";
public static final String PRODUCT_ID = "productId";
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
package com.axonivy.market.controller;

import static com.axonivy.market.constants.RequestMappingConstants.PRODUCT_JSON_CONTENT_BY_PRODUCT_ID_AND_VERSION;
import static com.axonivy.market.constants.RequestMappingConstants.VERSIONS_IN_DESIGNER;
import static com.axonivy.market.constants.RequestParamConstants.DESIGNER_VERSION;
import static com.axonivy.market.constants.RequestParamConstants.ID;
import static com.axonivy.market.constants.RequestParamConstants.PRODUCT_ID;
import static com.axonivy.market.constants.RequestParamConstants.SHOW_DEV_VERSION;
import static com.axonivy.market.constants.RequestParamConstants.VERSION;
import static com.axonivy.market.constants.RequestMappingConstants.BY_ID;
import static com.axonivy.market.constants.RequestMappingConstants.BY_ID_AND_VERSION;
import static com.axonivy.market.constants.RequestMappingConstants.INSTALLATION_COUNT_BY_ID;
import static com.axonivy.market.constants.RequestMappingConstants.PRODUCT_DETAILS;
import static com.axonivy.market.constants.RequestMappingConstants.VERSIONS_BY_ID;
import static com.axonivy.market.constants.RequestMappingConstants.BEST_MATCH_BY_ID_AND_VERSION;
import static com.axonivy.market.constants.RequestParamConstants.DESIGNER_VERSION;
import static com.axonivy.market.constants.RequestParamConstants.ID;
import static com.axonivy.market.constants.RequestParamConstants.SHOW_DEV_VERSION;
import static com.axonivy.market.constants.RequestParamConstants.VERSION;


import java.util.List;

import java.util.Map;
import com.fasterxml.jackson.core.JsonProcessingException;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
Expand Down Expand Up @@ -93,4 +95,20 @@ public ResponseEntity<List<MavenArtifactVersionModel>> findProductVersionsById(
versionService.getArtifactsAndVersionToDisplay(id, isShowDevVersion, designerVersion);
return new ResponseEntity<>(models, HttpStatus.OK);
}

@GetMapping(PRODUCT_JSON_CONTENT_BY_PRODUCT_ID_AND_VERSION)
@Operation(summary = "Get product json content for designer to install", description = "When we click install in designer, this API will send content of product json for installing in Ivy designer")
public ResponseEntity<Map<String, Object>> findProductJsonContent(@PathVariable(PRODUCT_ID) String productId,
@PathVariable(VERSION) String version) throws JsonProcessingException {
Map<String, Object> productJsonContent = versionService.getProductJsonContentByIdAndVersion(productId, version);
return new ResponseEntity<>(productJsonContent, HttpStatus.OK);
}

@GetMapping(VERSIONS_IN_DESIGNER)
@Operation(summary = "Get the list of released version in product", description = "Collect the released versions in product for ivy designer")
public ResponseEntity<List<String>> findVersionsForDesigner(@PathVariable(ID) String id) {
List<String> versionList = versionService.getVersionsForDesigner(id);
return new ResponseEntity<>(versionList, HttpStatus.OK);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.axonivy.market.entity.productjsonfilecontent;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;

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

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Document(PRODUCT_JSON_CONTENT)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ProductJsonContent {
@Id
@JsonIgnore
private String id;
private String version;
private String productId;
private String name;
private String content;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,20 @@
import com.axonivy.market.constants.ReadmeConstants;
import com.axonivy.market.entity.Product;
import com.axonivy.market.entity.ProductModuleContent;
import com.axonivy.market.entity.productjsonfilecontent.ProductJsonContent;
import com.axonivy.market.enums.Language;
import com.axonivy.market.enums.NonStandardProduct;
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.axonivy.market.repository.ProductJsonContentRepository;
import com.axonivy.market.util.VersionUtils;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.util.Strings;
import org.kohsuke.github.GHContent;
Expand All @@ -27,6 +32,7 @@

import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand All @@ -35,11 +41,16 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static com.axonivy.market.constants.ProductJsonConstants.EN_LANGUAGE;
import static com.axonivy.market.constants.ProductJsonConstants.VERSION_VALUE;

@Log4j2
@Service
public class GHAxonIvyProductRepoServiceImpl implements GHAxonIvyProductRepoService {
private GHOrganization organization;
private final GitHubService gitHubService;

private final ProductJsonContentRepository productJsonContentRepository;
private String repoUrl;
private static final ObjectMapper objectMapper = new ObjectMapper();
public static final String DEMO_SETUP_TITLE = "(?i)## Demo|## Setup";
Expand All @@ -50,8 +61,10 @@ public class GHAxonIvyProductRepoServiceImpl implements GHAxonIvyProductRepoServ
public static final String DEMO = "demo";
public static final String SETUP = "setup";

public GHAxonIvyProductRepoServiceImpl(GitHubService gitHubService) {
public GHAxonIvyProductRepoServiceImpl(GitHubService gitHubService,
ProductJsonContentRepository productJsonContentRepository) {
this.gitHubService = gitHubService;
this.productJsonContentRepository = productJsonContentRepository;
}

@Override
Expand Down Expand Up @@ -153,7 +166,7 @@ public ProductModuleContent getReadmeAndProductContentsFromTag(Product product,
try {
List<GHContent> contents = getProductFolderContents(product, ghRepository, tag);
productModuleContent.setTag(tag);
getDependencyContentsFromProductJson(productModuleContent, contents);
updateDependencyContentsFromProductJson(productModuleContent, contents , product);
List<GHContent> readmeFiles = contents.stream().filter(GHContent::isFile)
.filter(content -> content.getName().startsWith(ReadmeConstants.README_FILE_NAME)).toList();
Map<String,Map<String,String>> moduleContents = new HashMap<>();
Expand Down Expand Up @@ -200,8 +213,8 @@ private String getReadmeFileLocale(String readmeFile) {
return result;
}

private void getDependencyContentsFromProductJson(ProductModuleContent productModuleContent, List<GHContent> contents)
throws IOException {
private void updateDependencyContentsFromProductJson(ProductModuleContent productModuleContent,
List<GHContent> contents, Product product) throws IOException {
GHContent productJsonFile = getProductJsonFile(contents);
if (Objects.nonNull(productJsonFile)) {
List<MavenArtifact> artifacts = convertProductJsonToMavenProductInfo(productJsonFile);
Expand All @@ -214,6 +227,28 @@ private void getDependencyContentsFromProductJson(ProductModuleContent productMo
productModuleContent.setType(artifact.getType());
productModuleContent.setName(artifact.getName());
}
String currentVersion = VersionUtils.convertTagToVersion(productModuleContent.getTag());
boolean isProductJsonContentExists = productJsonContentRepository.existsByProductIdAndVersion(product.getId(),
currentVersion);
String content = extractProductJsonContent(productJsonFile, productModuleContent.getTag());
if (ObjectUtils.isNotEmpty(content) && !isProductJsonContentExists) {
ProductJsonContent jsonContent = new ProductJsonContent();
jsonContent.setVersion(currentVersion);
jsonContent.setProductId(product.getId());
jsonContent.setName(product.getNames().get(EN_LANGUAGE));
jsonContent.setContent(content.replace(VERSION_VALUE, currentVersion));
productJsonContentRepository.save(jsonContent);
}
}
}

public String extractProductJsonContent(GHContent ghContent, String tag) {
try {
InputStream contentStream = extractedContentStream(ghContent);
return IOUtils.toString(contentStream, StandardCharsets.UTF_8);
} catch (Exception exception) {
log.error("Cannot paste content of product.json {} at tag: {}", ghContent.getPath(), tag);
return null;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.axonivy.market.repository;

import com.axonivy.market.entity.productjsonfilecontent.ProductJsonContent;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface ProductJsonContentRepository extends MongoRepository<ProductJsonContent, String> {

ProductJsonContent findByProductIdAndVersion(String productId , String version);

boolean existsByProductIdAndVersion(String productId , String version);

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.axonivy.market.service;

import com.axonivy.market.model.MavenArtifactVersionModel;

import com.fasterxml.jackson.core.JsonProcessingException;
import java.util.List;
import java.util.Map;

public interface VersionService {

Expand All @@ -12,4 +13,9 @@ public interface VersionService {

List<MavenArtifactVersionModel> getArtifactsAndVersionToDisplay(String productId, Boolean isShowDevVersion,
String designerVersion);

Map<String, Object> getProductJsonContentByIdAndVersion(String name , String version)
throws JsonProcessingException;

List<String> getVersionsForDesigner(String productId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,25 @@
import com.axonivy.market.entity.MavenArtifactModel;
import com.axonivy.market.entity.MavenArtifactVersion;
import com.axonivy.market.entity.Product;
import com.axonivy.market.entity.ProductModuleContent;
import com.axonivy.market.entity.productjsonfilecontent.ProductJsonContent;
import com.axonivy.market.enums.NonStandardProduct;
import com.axonivy.market.github.model.ArchivedArtifact;
import com.axonivy.market.github.model.MavenArtifact;
import com.axonivy.market.github.service.GHAxonIvyProductRepoService;
import com.axonivy.market.github.util.GitHubUtils;
import com.axonivy.market.model.MavenArtifactVersionModel;
import com.axonivy.market.repository.MavenArtifactVersionRepository;
import com.axonivy.market.repository.ProductJsonContentRepository;
import com.axonivy.market.repository.ProductRepository;
import com.axonivy.market.service.VersionService;
import com.axonivy.market.util.VersionUtils;
import com.axonivy.market.util.XmlReaderUtils;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Getter;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.kohsuke.github.GHContent;
import org.springframework.stereotype.Service;
Expand All @@ -37,6 +43,8 @@
import java.util.Optional;
import java.util.Set;

import static com.axonivy.market.constants.ProductJsonConstants.NAME;

@Log4j2
@Service
@Getter
Expand All @@ -45,6 +53,7 @@ public class VersionServiceImpl implements VersionService {
private final GHAxonIvyProductRepoService gitHubService;
private final MavenArtifactVersionRepository mavenArtifactVersionRepository;
private final ProductRepository productRepository;
private final ProductJsonContentRepository productJsonContentRepository;
@Getter
private String repoName;
private Map<String, List<ArchivedArtifact>> archivedArtifactsMap;
Expand All @@ -55,13 +64,16 @@ public class VersionServiceImpl implements VersionService {
@Getter
private String productJsonFilePath;
private String productId;
private final ObjectMapper mapper = new ObjectMapper();

public VersionServiceImpl(GHAxonIvyProductRepoService gitHubService,
MavenArtifactVersionRepository mavenArtifactVersionRepository, ProductRepository productRepository) {
MavenArtifactVersionRepository mavenArtifactVersionRepository, ProductRepository productRepository,
ProductJsonContentRepository productJsonContentRepository) {
this.gitHubService = gitHubService;
this.mavenArtifactVersionRepository = mavenArtifactVersionRepository;
this.productRepository = productRepository;

this.productJsonContentRepository = productJsonContentRepository;
}

private void resetData() {
Expand Down Expand Up @@ -96,6 +108,23 @@ public List<MavenArtifactVersionModel> getArtifactsAndVersionToDisplay(String pr
return results;
}

@Override
public Map<String, Object> getProductJsonContentByIdAndVersion(String productId, String version)
throws JsonProcessingException {
ProductJsonContent productJsonContent = productJsonContentRepository.findByProductIdAndVersion(productId, version);
if (ObjectUtils.isEmpty(productJsonContent)) {
return new HashMap<>();
}
Map<String, Object> result = mapper.readValue(productJsonContent.getContent(), Map.class);
result.computeIfAbsent(NAME, k -> productJsonContent.getName());
return result;
}

@Override
public List<String> getVersionsForDesigner(String productId) {
return productRepository.getReleasedVersionsById(productId);
}

public boolean handleArtifactForVersionToDisplay(List<String> versionsToDisplay,
List<MavenArtifactVersionModel> result) {
boolean isNewVersionDetected = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ market.github.oauth2-clientId=${MARKET_GITHUB_OAUTH_APP_CLIENT_ID}
market.github.oauth2-clientSecret=${MARKET_GITHUB_OAUTH_APP_CLIENT_SECRET}
jwt.secret=${MARKET_JWT_SECRET_KEY}
jwt.expiration=365
logging.level.org.springframework.data.mongodb.core.MongoTemplate=DEBUG
logging.level.org.springframework.data.mongodb.core.MongoTemplate=DEBUG
spring.jackson.serialization.indent_output=true
Loading

0 comments on commit e115999

Please sign in to comment.