Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into feature/MARP-947-R…
Browse files Browse the repository at this point in the history
…e-structure-ProductModuleContent-in-Product

# Conflicts:
#	marketplace-service/src/main/java/com/axonivy/market/entity/Product.java
  • Loading branch information
tutn-axonivy committed Aug 30, 2024
2 parents 7d0039c + 84b2794 commit a7a6621
Show file tree
Hide file tree
Showing 28 changed files with 171 additions and 61 deletions.
2 changes: 2 additions & 0 deletions marketplace-build/config/nginx/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ http {
location /marketplace-service {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://service:8080/marketplace-service;
proxy_ssl_session_reuse off;
Expand Down
2 changes: 2 additions & 0 deletions marketplace-build/release/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ services:

ui:
image: ghcr.io/axonivy-market/marketplace-ui:${RELEASE_VERSION}
volumes:
- ../config/nginx/nginx.conf:/etc/nginx/nginx.conf
restart: always
ports:
- "80:80"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
import com.axonivy.market.controller.ProductDetailsController;
import com.axonivy.market.entity.Product;
import com.axonivy.market.model.ProductDetailModel;
import com.axonivy.market.util.VersionUtils;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.StringUtils;
import org.springframework.hateoas.Link;
import org.springframework.hateoas.server.mvc.RepresentationModelAssemblerSupport;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
Expand All @@ -16,6 +19,7 @@
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn;

@Component
@Log4j2
public class ProductDetailModelAssembler extends RepresentationModelAssemblerSupport<Product, ProductDetailModel> {

private final ProductModelAssembler productModelAssembler;
Expand Down Expand Up @@ -43,14 +47,22 @@ private ProductDetailModel createModel(Product product, String version, String r
ProductDetailModel model = instantiateModel(product);
productModelAssembler.createResource(model, product);
String productId = Optional.of(product).map(Product::getId).orElse(StringUtils.EMPTY);

if (requestPath.equals(RequestMappingConstants.BEST_MATCH_BY_ID_AND_VERSION)) {
String bestMatchVersion = VersionUtils.getBestMatchVersion(product.getReleasedVersions(), version);
Link link = linkTo(
methodOn(ProductDetailsController.class).findProductJsonContent(productId, bestMatchVersion)).withSelfRel();
model.setMetaProductJsonUrl(link.getHref());
}

selfLinkWithTag = switch (requestPath) {
case RequestMappingConstants.BEST_MATCH_BY_ID_AND_VERSION ->
methodOn(ProductDetailsController.class).findBestMatchProductDetailsByVersion(productId, version);
case RequestMappingConstants.BY_ID_AND_VERSION ->
methodOn(ProductDetailsController.class).findProductDetailsByVersion(productId, version);
default ->
methodOn(ProductDetailsController.class).findProductDetails(productId);
default -> methodOn(ProductDetailsController.class).findProductDetails(productId);
};

model.add(linkTo(selfLinkWithTag).withSelfRel());
createDetailResource(model, product);
return model;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
import static com.axonivy.market.constants.RequestMappingConstants.BEST_MATCH_BY_ID_AND_VERSION;
import java.util.List;
import java.util.Map;
import com.fasterxml.jackson.core.JsonProcessingException;

import com.axonivy.market.model.VersionAndUrlModel;
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 @@ -99,15 +100,15 @@ public ResponseEntity<List<MavenArtifactVersionModel>> findProductVersionsById(
@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 {
@PathVariable(VERSION) String version) {
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);
public ResponseEntity<List<VersionAndUrlModel>> findVersionsForDesigner(@PathVariable(ID) String id) {
List<VersionAndUrlModel> versionList = versionService.getVersionsForDesigner(id);
return new ResponseEntity<>(versionList, HttpStatus.OK);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Transient;
import org.springframework.data.mongodb.core.mapping.DBRef;
import org.springframework.data.mongodb.core.mapping.Document;

Expand Down Expand Up @@ -64,6 +65,9 @@ public class Product implements Serializable {
private Integer customOrder;
private List<String> releasedVersions;

@Transient
private String metaProductJsonUrl;

@Override
public int hashCode() {
return new HashCodeBuilder().append(id).hashCode();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.axonivy.market.entity.productjsonfilecontent;
package com.axonivy.market.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
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.entity.ProductJsonContent;
import com.axonivy.market.enums.Language;
import com.axonivy.market.enums.NonStandardProduct;
import com.axonivy.market.github.model.MavenArtifact;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public class ProductDetailModel extends ProductModel {
private ProductModuleContent productModuleContent;
@Schema(description = "Installation/download count", example = "0")
private int installationCount;
@Schema(description = "The api url to get metadata from product.json")
private String metaProductJsonUrl;

@Override
public int hashCode() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.axonivy.market.model;

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

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class VersionAndUrlModel {
String version;
String url;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.axonivy.market.repository;

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.axonivy.market.service;

import com.axonivy.market.model.MavenArtifactVersionModel;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.axonivy.market.model.VersionAndUrlModel;
import java.util.List;
import java.util.Map;

Expand All @@ -14,8 +14,7 @@ public interface VersionService {
List<MavenArtifactVersionModel> getArtifactsAndVersionToDisplay(String productId, Boolean isShowDevVersion,
String designerVersion);

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

List<String> getVersionsForDesigner(String productId);
List<VersionAndUrlModel> getVersionsForDesigner(String productId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@
import com.axonivy.market.constants.CommonConstants;
import com.axonivy.market.constants.GitHubConstants;
import com.axonivy.market.constants.MavenConstants;
import com.axonivy.market.controller.ProductDetailsController;
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.entity.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.model.VersionAndUrlModel;
import com.axonivy.market.repository.MavenArtifactVersionRepository;
import com.axonivy.market.repository.ProductJsonContentRepository;
import com.axonivy.market.repository.ProductRepository;
Expand All @@ -29,6 +30,7 @@
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.kohsuke.github.GHContent;
import org.springframework.hateoas.Link;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

Expand All @@ -44,7 +46,8 @@
import java.util.Set;

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

import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn;
@Log4j2
@Service
@Getter
Expand Down Expand Up @@ -109,20 +112,33 @@ public List<MavenArtifactVersionModel> getArtifactsAndVersionToDisplay(String pr
}

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

} catch (JsonProcessingException jsonProcessingException){
log.error(jsonProcessingException.getMessage());
}
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 List<VersionAndUrlModel> getVersionsForDesigner(String productId) {
List<VersionAndUrlModel> versionAndUrlList = new ArrayList<>();
List<String> versions = productRepository.getReleasedVersionsById(productId);
for (String version : versions) {
Link link = linkTo(
methodOn(ProductDetailsController.class).findProductJsonContent(productId, version)).withSelfRel();
VersionAndUrlModel versionAndUrlModel = new VersionAndUrlModel(version, link.getHref());
versionAndUrlList.add(versionAndUrlModel);
}
return versionAndUrlList;
}

public boolean handleArtifactForVersionToDisplay(List<String> versionsToDisplay,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import org.mockito.InjectMocks;
import org.mockito.junit.jupiter.MockitoExtension;

import java.util.List;

@ExtendWith(MockitoExtension.class)
class ProductDetailModelAssemblerTest {
private static final String ID = "portal";
Expand All @@ -25,6 +27,7 @@ void setup() {
productDetailModelAssembler = new ProductDetailModelAssembler(new ProductModelAssembler());
mockProduct = new Product();
mockProduct.setId(ID);
mockProduct.setReleasedVersions(List.of("11.0.1", "10.0.8"));
}

@Test
Expand All @@ -51,5 +54,6 @@ void testToModelWithRequestPathAndVersion() {
void testToModelWithRequestPathAndBestMatchVersion() {
ProductDetailModel model = productDetailModelAssembler.toModel(mockProduct, VERSION, RequestMappingConstants.BEST_MATCH_BY_ID_AND_VERSION);
Assertions.assertTrue(model.getLink(SELF_RELATION).get().getHref().endsWith("/api/product-details/portal/10.0.19/bestmatch"));
Assertions.assertTrue(model.getMetaProductJsonUrl().endsWith("/api/product-details/productjsoncontent/portal/10.0.8"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
import java.util.HashMap;
import java.util.Map;
import com.axonivy.market.constants.RequestMappingConstants;
import com.axonivy.market.entity.productjsonfilecontent.ProductJsonContent;
import com.axonivy.market.entity.ProductJsonContent;
import com.axonivy.market.model.VersionAndUrlModel;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -124,15 +125,31 @@ void testSyncInstallationCount() {

@Test
void findProductVersionsById() {
when(versionService.getVersionsForDesigner("google-maps-connector")).thenReturn(
List.of("10.0.21", "10.0.22", "10.0.23"));
when(versionService.getVersionsForDesigner("google-maps-connector")).thenReturn(mockVersionAndUrlModels());

var result = productDetailsController.findVersionsForDesigner("google-maps-connector");

assertEquals(3, Objects.requireNonNull(result.getBody()).size());
assertEquals("10.0.21", Objects.requireNonNull(result.getBody()).get(0));
assertEquals("10.0.22", Objects.requireNonNull(result.getBody()).get(1));
assertEquals("10.0.23", Objects.requireNonNull(result.getBody()).get(2));
assertEquals(2, Objects.requireNonNull(result.getBody()).size());
assertEquals("10.0.21", Objects.requireNonNull(result.getBody()).get(0).getVersion());
assertEquals("/api/product-details/productjsoncontent/portal/10.0.21",
Objects.requireNonNull(result.getBody()).get(0).getUrl());
assertEquals("10.0.22", Objects.requireNonNull(result.getBody()).get(1).getVersion());
assertEquals("/api/product-details/productjsoncontent/portal/10.0.22",
Objects.requireNonNull(result.getBody()).get(1).getUrl());
}

private List<VersionAndUrlModel> mockVersionAndUrlModels(){
VersionAndUrlModel versionAndUrlModel = VersionAndUrlModel.builder()
.version("10.0.21")
.url("/api/product-details/productjsoncontent/portal/10.0.21")
.build();

VersionAndUrlModel versionAndUrlModel2 = VersionAndUrlModel.builder()
.version("10.0.22")
.url("/api/product-details/productjsoncontent/portal/10.0.22")
.build();

return List.of(versionAndUrlModel,versionAndUrlModel2);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.axonivy.market.constants.ProductJsonConstants;
import com.axonivy.market.constants.ReadmeConstants;
import com.axonivy.market.entity.Product;
import com.axonivy.market.entity.productjsonfilecontent.ProductJsonContent;
import com.axonivy.market.entity.ProductJsonContent;
import com.axonivy.market.enums.Language;
import com.axonivy.market.github.model.MavenArtifact;
import com.axonivy.market.github.service.GitHubService;
Expand Down
Loading

0 comments on commit a7a6621

Please sign in to comment.