diff --git a/marketplace-service/src/main/java/com/axonivy/market/assembler/ProductDetailModelAssembler.java b/marketplace-service/src/main/java/com/axonivy/market/assembler/ProductDetailModelAssembler.java index 36de4e9d3..13d46bcfb 100644 --- a/marketplace-service/src/main/java/com/axonivy/market/assembler/ProductDetailModelAssembler.java +++ b/marketplace-service/src/main/java/com/axonivy/market/assembler/ProductDetailModelAssembler.java @@ -13,6 +13,7 @@ import org.springframework.stereotype.Component; import java.util.List; +import java.util.Optional; import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo; import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn; @@ -32,8 +33,9 @@ public ProductDetailModel toModel(Product product) { return createModel(product, null); } - public ProductDetailModel toModel(Product product, String tag) { - return createModel(product, tag); + public ProductDetailModel toModel(Product product, String version) { + String productId = Optional.ofNullable(product).map(Product::getId).orElse(StringUtils.EMPTY); + return createModel(product, convertVersionToTag(productId, version)); } private ProductDetailModel createModel(Product product, String tag) { diff --git a/marketplace-service/src/main/java/com/axonivy/market/constants/GitHubConstants.java b/marketplace-service/src/main/java/com/axonivy/market/constants/GitHubConstants.java index 9aed8ec2f..bd6ab9937 100644 --- a/marketplace-service/src/main/java/com/axonivy/market/constants/GitHubConstants.java +++ b/marketplace-service/src/main/java/com/axonivy/market/constants/GitHubConstants.java @@ -14,6 +14,7 @@ public class GitHubConstants { public static final String GITHUB_GET_ACCESS_TOKEN_URL = "https://github.com/login/oauth/access_token"; public static final String README_FILE_LOCALE_REGEX = "_(..)"; public static final String STANDARD_TAG_PREFIX = "v"; + public static final String COMMON_IMAGES_FOLDER_NAME = "images"; @NoArgsConstructor(access = AccessLevel.PRIVATE) public static class Json { diff --git a/marketplace-service/src/main/java/com/axonivy/market/controller/ProductDetailsController.java b/marketplace-service/src/main/java/com/axonivy/market/controller/ProductDetailsController.java index 2a97656ff..7bc114b6b 100644 --- a/marketplace-service/src/main/java/com/axonivy/market/controller/ProductDetailsController.java +++ b/marketplace-service/src/main/java/com/axonivy/market/controller/ProductDetailsController.java @@ -8,13 +8,8 @@ import io.swagger.v3.oas.annotations.Operation; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.bind.annotation.CrossOrigin; +import org.springframework.web.bind.annotation.*; + import java.util.List; import static com.axonivy.market.constants.RequestMappingConstants.PRODUCT_DETAILS; @@ -51,7 +46,7 @@ public ResponseEntity syncInstallationCount(@PathVariable("key") String @GetMapping("/{id}") public ResponseEntity findProductDetails(@PathVariable("id") String id) { var productDetail = productService.fetchProductDetail(id); - return new ResponseEntity<>(detailModelAssembler.toModel(productDetail, null), HttpStatus.OK); + return new ResponseEntity<>(detailModelAssembler.toModel(productDetail), HttpStatus.OK); } @GetMapping("/{id}/versions") diff --git a/marketplace-service/src/main/java/com/axonivy/market/enums/NonStandardProduct.java b/marketplace-service/src/main/java/com/axonivy/market/enums/NonStandardProduct.java index 1eb83d05e..9a2da0bbd 100644 --- a/marketplace-service/src/main/java/com/axonivy/market/enums/NonStandardProduct.java +++ b/marketplace-service/src/main/java/com/axonivy/market/enums/NonStandardProduct.java @@ -5,38 +5,41 @@ import java.util.Arrays; +import static com.axonivy.market.constants.GitHubConstants.COMMON_IMAGES_FOLDER_NAME; + @Getter @AllArgsConstructor public enum NonStandardProduct { - PORTAL ( "portal",true,"images","AxonIvyPortal/portal-product" ), - MICROSOFT_REPO_NAME ( "msgraph-connector",false,"images",""), - MICROSOFT_365 ( "msgraph",false,"images","msgraph-connector-product/products/msgraph-connector"), // No meta.json - MICROSOFT_CALENDAR ( "msgraph-calendar",false,"images","msgraph-connector-product/products/msgraph-calendar"), // no fix product json - MICROSOFT_MAIL ( "msgraph-mail",false,"images","msgraph-connector-product/products/msgraph-mail"),// no fix product json - MICROSOFT_TEAMS ( "msgraph-chat",false,"images","msgraph-connector-product/products/msgraph-chat"),// no fix product json - MICROSOFT_TODO ( "msgraph-todo",false,"images","msgraph-connector-product/products/msgraph-todo"),// no fix product json - CONNECTIVITY_FEATURE ( "connectivity-demo",false,"images","connectivity/connectivity-demos-product"), - EMPLOYEE_ONBOARDING ( "employee-onboarding",false,"images",""), // Invalid meta.json - ERROR_HANDLING ( "error-handling-demo",false,"images","error-handling/error-handling-demos-product"), - RULE_ENGINE_DEMOS ( "rule-engine-demo",false,"images","rule-engine/rule-engine-demos-product"), - WORKFLOW_DEMO ( "workflow-demo",false,"images","workflow/workflow-demos-product"), - HTML_DIALOG_DEMO ( "html-dialog-demo",false,"images","html-dialog/html-dialog-demos-product"), - PROCESSING_VALVE_DEMO ( "processing-valve-demo",false,"images",""),// no product json - OPENAI_CONNECTOR ( "openai-connector",false,"images","openai-connector-product"), - OPENAI_ASSISTANT ( "openai-assistant",false,"docs","openai-assistant-product"), + PORTAL("portal", true, COMMON_IMAGES_FOLDER_NAME, "AxonIvyPortal/portal-product"), + MICROSOFT_REPO_NAME("msgraph-connector", false, COMMON_IMAGES_FOLDER_NAME, ""), + MICROSOFT_365("msgraph", false, COMMON_IMAGES_FOLDER_NAME, "msgraph-connector-product/products/msgraph-connector"), // No meta.json + MICROSOFT_CALENDAR("msgraph-calendar", false, COMMON_IMAGES_FOLDER_NAME, "msgraph-connector-product/products/msgraph-calendar"), // no fix product json + MICROSOFT_MAIL("msgraph-mail", false, COMMON_IMAGES_FOLDER_NAME, "msgraph-connector-product/products/msgraph-mail"),// no fix product json + MICROSOFT_TEAMS("msgraph-chat", false, COMMON_IMAGES_FOLDER_NAME, "msgraph-connector-product/products/msgraph-chat"),// no fix product json + MICROSOFT_TODO("msgraph-todo", false, COMMON_IMAGES_FOLDER_NAME, "msgraph-connector-product/products/msgraph-todo"),// no fix product json + CONNECTIVITY_FEATURE("connectivity-demo", false, COMMON_IMAGES_FOLDER_NAME, "connectivity/connectivity-demos-product"), + EMPLOYEE_ONBOARDING("employee-onboarding", false, COMMON_IMAGES_FOLDER_NAME, ""), // Invalid meta.json + ERROR_HANDLING("error-handling-demo", false, COMMON_IMAGES_FOLDER_NAME, "error-handling/error-handling-demos-product"), + RULE_ENGINE_DEMOS("rule-engine-demo", false, COMMON_IMAGES_FOLDER_NAME, "rule-engine/rule-engine-demos-product"), + WORKFLOW_DEMO("workflow-demo", false, COMMON_IMAGES_FOLDER_NAME, "workflow/workflow-demos-product"), + HTML_DIALOG_DEMO("html-dialog-demo", false, COMMON_IMAGES_FOLDER_NAME, "html-dialog/html-dialog-demos-product"), + PROCESSING_VALVE_DEMO("processing-valve-demo", false, COMMON_IMAGES_FOLDER_NAME, ""),// no product json + OPENAI_CONNECTOR("openai-connector", false, COMMON_IMAGES_FOLDER_NAME, "openai-connector-product"), + OPENAI_ASSISTANT("openai-assistant", false, "docs", "openai-assistant-product"), // Non standard image folder name - EXCEL_IMPORTER ( "excel-importer",false,"doc",""), - EXPRESS_IMPORTER ( "express-importer",false,"img",""), - GRAPHQL_DEMO ( "graphql-demo",false,"assets",""), - DEEPL_CONNECTOR ( "deepl-connector",false,"img",""), - DEFAULT("",false,"images",""); + EXCEL_IMPORTER("excel-importer", false, "doc", ""), + EXPRESS_IMPORTER("express-importer", false, "img", ""), + GRAPHQL_DEMO("graphql-demo", false, "assets", ""), + DEEPL_CONNECTOR("deepl-connector", false, "img", ""), + DEFAULT("", false, COMMON_IMAGES_FOLDER_NAME, ""); private final String id; private final boolean isVersionTagNumberOnly; private final String pathToImageFolder; private final String pathToProductFolder; - public static NonStandardProduct findById(String id){ + public static NonStandardProduct findById(String id) { + return Arrays.stream(NonStandardProduct.values()).filter(product -> id.equalsIgnoreCase(product.getId())).findAny().orElse(DEFAULT); } }