Skip to content

Commit

Permalink
Merge branch 'develop' into feature/MARP-473-follow-up-for-marp-264-i…
Browse files Browse the repository at this point in the history
…nstallation-frequency-providing-data
  • Loading branch information
tvtphuc-axonivy committed Jul 12, 2024
2 parents 87709bf + 8dfcb3b commit dcc19f3
Show file tree
Hide file tree
Showing 32 changed files with 2,310 additions and 1,559 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package com.axonivy.market.assembler;

import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn;

import com.axonivy.market.controller.ProductDetailsController;
import com.axonivy.market.entity.Product;
import com.axonivy.market.entity.ProductModuleContent;
import com.axonivy.market.model.ProductDetailModel;
import org.apache.commons.lang3.StringUtils;
import org.springframework.hateoas.server.mvc.RepresentationModelAssemblerSupport;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;

import java.util.List;

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

private final ProductModelAssembler productModelAssembler;

public ProductDetailModelAssembler(ProductModelAssembler productModelAssembler) {
super(ProductDetailsController.class, ProductDetailModel.class);
this.productModelAssembler = productModelAssembler;
}

@Override
public ProductDetailModel toModel(Product product) {
return createModel(product, null);
}

public ProductDetailModel toModel(Product product, String tag) {
return createModel(product, tag);
}

private ProductDetailModel createModel(Product product, String tag) {
ResponseEntity<ProductDetailModel> selfLinkWithTag;
ProductDetailModel model = instantiateModel(product);
productModelAssembler.createResource(model, product);
if (StringUtils.isBlank(tag)) {
selfLinkWithTag = methodOn(ProductDetailsController.class).findProductDetails(product.getId());
} else {
selfLinkWithTag = methodOn(ProductDetailsController.class).findProductDetailsByVersion(product.getId(), tag);
}
model.add(linkTo(selfLinkWithTag).withSelfRel());
createDetailResource(model, product, tag);
return model;
}

private void createDetailResource(ProductDetailModel model, Product product, String tag) {
model.setVendor(product.getVendor());
model.setNewestReleaseVersion(product.getNewestReleaseVersion());
model.setPlatformReview(product.getPlatformReview());
model.setSourceUrl(product.getSourceUrl());
model.setStatusBadgeUrl(product.getStatusBadgeUrl());
model.setLanguage(product.getLanguage());
model.setIndustry(product.getIndustry());
model.setCompatibility(product.getCompatibility());
model.setContactUs(product.getContactUs());
model.setCost(product.getCost());

if (StringUtils.isBlank(tag) && StringUtils.isNotBlank(product.getNewestReleaseVersion())) {
tag = product.getNewestReleaseVersion();
}
ProductModuleContent content = getProductModuleContentByTag(product.getProductModuleContents(), tag);
model.setProductModuleContent(content);
}

private ProductModuleContent getProductModuleContentByTag(List<ProductModuleContent> contents, String tag) {
return contents.stream().filter(content -> StringUtils.equals(content.getTag(), tag)).findAny().orElse(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ public ProductModelAssembler() {
@Override
public ProductModel toModel(Product product) {
ProductModel resource = new ProductModel();
resource.add(linkTo(methodOn(ProductDetailsController.class).findProduct(product.getId(), product.getType()))
.withSelfRel());
resource.add(linkTo(methodOn(ProductDetailsController.class).findProductDetails(product.getId())).withSelfRel());
return createResource(resource, product);
}

private ProductModel createResource(ProductModel model, Product product) {
public ProductModel createResource(ProductModel model, Product product) {
model.setId(product.getId());
model.setNames(product.getNames());
model.setShortDescriptions(product.getShortDescriptions());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +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 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
@@ -1,19 +1,14 @@
package com.axonivy.market.constants;

public class MavenConstants {
private MavenConstants() {
}
private MavenConstants() {}

public static final String SNAPSHOT_RELEASE_POSTFIX = "-SNAPSHOT";
public static final String SPRINT_RELEASE_POSTFIX = "-m";
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()";
public static final String SNAPSHOT_RELEASE_POSTFIX = "-SNAPSHOT";
public static final String SPRINT_RELEASE_POSTFIX = "-m";
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 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()";
}
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,20 +1,27 @@
package com.axonivy.market.constants;

public class NonStandardProductPackageConstants {
private NonStandardProductPackageConstants() {
}
private NonStandardProductPackageConstants() {}

public static final String PORTAL = "portal";
public static final String MICROSOFT_365 = ""; // No meta.json
public static final String MICROSOFT_CALENDAR = "msgraph-calendar"; // no fix product json
public static final String MICROSOFT_MAIL = "msgraph-mail";// no fix product json
public static final String MICROSOFT_TEAMS = "msgraph-chat";// no fix product json
public static final String MICROSOFT_TODO = "msgraph-todo";// no fix product json
public static final String CONNECTIVITY_FEATURE = "connectivity-demo";
public static final String EMPLOYEE_ONBOARDING = "employee-onboarding"; // Invalid meta.json
public static final String ERROR_HANDLING = "error-handling-demo";
public static final String RULE_ENGINE_DEMOS = "rule-engine-demo";
public static final String WORKFLOW_DEMO = "workflow-demo";
public static final String HTML_DIALOG_DEMO = "html-dialog-demo";
public static final String PROCESSING_VALVE_DEMO = "processing-valve-demo";// no product json
}
public static final String PORTAL = "portal";
public static final String MICROSOFT_REPO_NAME = "msgraph-connector";
public static final String MICROSOFT_365 = "msgraph"; // No meta.json
public static final String MICROSOFT_CALENDAR = "msgraph-calendar"; // no fix product json
public static final String MICROSOFT_MAIL = "msgraph-mail";// no fix product json
public static final String MICROSOFT_TEAMS = "msgraph-chat";// no fix product json
public static final String MICROSOFT_TODO = "msgraph-todo";// no fix product json
public static final String CONNECTIVITY_FEATURE = "connectivity-demo";
public static final String EMPLOYEE_ONBOARDING = "employee-onboarding"; // Invalid meta.json
public static final String ERROR_HANDLING = "error-handling-demo";
public static final String RULE_ENGINE_DEMOS = "rule-engine-demo";
public static final String WORKFLOW_DEMO = "workflow-demo";
public static final String HTML_DIALOG_DEMO = "html-dialog-demo";
public static final String PROCESSING_VALVE_DEMO = "processing-valve-demo";// no product json
public static final String OPENAI_CONNECTOR = "openai-connector";
public static final String OPENAI_ASSISTANT = "openai-assistant";
// Non standard image folder name
public static final String EXCEL_IMPORTER = "excel-importer";
public static final String EXPRESS_IMPORTER = "express-importer";
public static final String GRAPHQL_DEMO = "graphql-demo";
public static final String DEEPL_CONNECTOR = "deepl-connector";
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
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";
public static final String ID = "id";
public static final String PROJECTS = "projects";
public static final String ARTIFACT_ID = "artifactId";
public static final String GROUP_ID = "groupId";
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";

public static final String DATA = "data";
public static final String REPOSITORIES = "repositories";
public static final String URL = "url";
public static final String ID = "id";
public static final String PROJECTS = "projects";
public static final String ARTIFACT_ID = "artifactId";
public static final String GROUP_ID = "groupId";
public static final String TYPE = "type";
public static final String DEPENDENCIES = "dependencies";
public static final String INSTALLERS = "installers";
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";

private ProductJsonConstants() {
}
private ProductJsonConstants() {}
}
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";
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ public ResponseEntity<Message> syncProducts() {

@SuppressWarnings("unchecked")
private ResponseEntity<PagedModel<ProductModel>> generateEmptyPagedModel() {
var emptyPagedModel = (PagedModel<ProductModel>) pagedResourcesAssembler
.toEmptyModel(Page.empty(), ProductModel.class);
var emptyPagedModel =
(PagedModel<ProductModel>) pagedResourcesAssembler.toEmptyModel(Page.empty(), ProductModel.class);
return new ResponseEntity<>(emptyPagedModel, HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.axonivy.market.assembler.ProductDetailModelAssembler;
import com.axonivy.market.model.ProductDetailModel;
import com.axonivy.market.service.ProductService;

import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;

Expand All @@ -15,32 +24,42 @@
@RestController
@RequestMapping(PRODUCT_DETAILS)
public class ProductDetailsController {
private final VersionService versionService;
private final ProductService productService;
public ProductDetailsController(VersionService versionService, ProductService productService) {
this.versionService = versionService;
this.productService = productService;
}
private final VersionService versionService;
private final ProductService productService;
private final ProductDetailModelAssembler detailModelAssembler;

@GetMapping("/{id}")
public ResponseEntity<Object> findProduct(@PathVariable("id") String key,
@RequestParam(name = "type", required = false) String type) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
public ProductDetailsController(VersionService versionService, ProductService productService,
ProductDetailModelAssembler detailModelAssembler) {
this.versionService = versionService;
this.productService = productService;
this.detailModelAssembler = detailModelAssembler;
}

@GetMapping("/{id}/versions")
public ResponseEntity<List<MavenArtifactVersionModel>> findProductVersionsById(@PathVariable("id") String id,
@RequestParam(name = "isShowDevVersion") boolean isShowDevVersion,
@RequestParam(name = "designerVersion", required = false) String designerVersion) {
List<MavenArtifactVersionModel> models = versionService.getArtifactsAndVersionToDisplay(id, isShowDevVersion,
designerVersion);
return new ResponseEntity<>(models, HttpStatus.OK);
}
@GetMapping("/{id}/{tag}")
public ResponseEntity<ProductDetailModel> findProductDetailsByVersion(@PathVariable("id") String id,
@PathVariable("tag") String tag) {
var productDetail = productService.fetchProductDetail(id);
return new ResponseEntity<>(detailModelAssembler.toModel(productDetail, tag), HttpStatus.OK);
}

@Operation(summary = "increase installation count by 1", description = "increase installation count by 1")
@PutMapping("/installationcount/{key}")
public ResponseEntity<Integer> syncInstallationCount(@PathVariable("key") String key) {
int result = productService.updateInstallationCountForProduct(key);
return new ResponseEntity<>(result, HttpStatus.OK);
}
}
@GetMapping("/{id}")
public ResponseEntity<ProductDetailModel> findProductDetails(@PathVariable("id") String id) {
var productDetail = productService.fetchProductDetail(id);
return new ResponseEntity<>(detailModelAssembler.toModel(productDetail, null), HttpStatus.OK);
}

@GetMapping("/{id}/versions")
public ResponseEntity<List<MavenArtifactVersionModel>> findProductVersionsById(@PathVariable("id") String id,
@RequestParam(name = "isShowDevVersion") boolean isShowDevVersion,
@RequestParam(name = "designerVersion", required = false) String designerVersion) {
List<MavenArtifactVersionModel> models =
versionService.getArtifactsAndVersionToDisplay(id, isShowDevVersion, designerVersion);
return new ResponseEntity<>(models, HttpStatus.OK);
}
}
Loading

0 comments on commit dcc19f3

Please sign in to comment.