Skip to content

Commit

Permalink
MARP-1067 market website can not download install artifact snapshot
Browse files Browse the repository at this point in the history
Co-authored-by: nntthuy-axonivy <[email protected]>
  • Loading branch information
ntqdinh-axonivy and nntthuy-axonivy authored Sep 30, 2024
1 parent 4294e49 commit 735fb43
Show file tree
Hide file tree
Showing 75 changed files with 2,862 additions and 895 deletions.
1 change: 1 addition & 0 deletions marketplace-service/.dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
target/
data/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
Expand Down
1 change: 1 addition & 0 deletions marketplace-service/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
target/
data/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.axonivy.market;

import com.axonivy.market.service.ProductService;
import lombok.AllArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.time.StopWatch;
import org.springframework.boot.SpringApplication;
Expand All @@ -15,14 +16,11 @@
@EnableAsync
@EnableScheduling
@SpringBootApplication
@AllArgsConstructor
public class MarketplaceServiceApplication {

private final ProductService productService;

public MarketplaceServiceApplication(ProductService productService) {
this.productService = productService;
}

public static void main(String[] args) {
SpringApplication.run(MarketplaceServiceApplication.class, args);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ private ProductDetailModel createModel(Product product, String version, String r
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();
methodOn(ProductDetailsController.class).findProductJsonContent(productId,
product.getBestMatchVersion())).withSelfRel();
model.setMetaProductJsonUrl(link.getHref());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.axonivy.market.github.model;
package com.axonivy.market.bo;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.axonivy.market.github.model;
package com.axonivy.market.bo;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
Expand All @@ -11,14 +11,15 @@
import java.io.Serial;
import java.io.Serializable;
import java.util.List;
import java.util.Objects;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonIgnoreProperties(ignoreUnknown = true)
public class MavenArtifact implements Serializable {
public class Artifact implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
private String repoUrl;
Expand All @@ -30,4 +31,22 @@ public class MavenArtifact implements Serializable {
@Transient
private Boolean isProductArtifact;
private List<ArchivedArtifact> archivedArtifacts;
private boolean isInvalidArtifact;

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Artifact that = (Artifact) o;
return Objects.equals(groupId, that.groupId) && Objects.equals(artifactId, that.artifactId);
}

@Override
public int hashCode() {
return Objects.hash(groupId, artifactId);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class CommonConstants {
public static final String BEARER = "Bearer";
public static final String DIGIT_REGEX = "([0-9]+.*)";
public static final String IMAGE_ID_PREFIX = "imageId-";
public static final String IMAGE_EXTENSION = "(.*?).(jpeg|jpg|png|gif)";
public static final String ID_WITH_NUMBER_PATTERN = "%s-%s";
public static final String ERROR = "error";
public static final String MESSAGE = "message";
Expand Down
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 DirectoryConstants {
public static final String DATA_DIR = "data";
public static final String WORK_DIR = "work";

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ public class EntityConstants {
public static final String USER = "User";
public static final String PRODUCT = "Product";
public static final String PRODUCT_DESIGNER_INSTALLATION = "ProductDesignerInstallation";
public static final String MAVEN_ARTIFACT_VERSION = "MavenArtifactVersion";
public static final String MAVEN_METADATA_SYNC = "MavenMetadataSync";
public static final String METADATA = "Metadata";
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";
public static final String PRODUCT_MODULE_CONTENT = "ProductModuleContent";
public static final String IMAGE = "Image";
public static final String MAVEN_ARTIFACT_VERSION = "MavenArtifactVersion";
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ public class GitHubConstants {
public static final String AXONIVY_MARKET_ORGANIZATION_NAME = "axonivy-market";
public static final String AXONIVY_MARKETPLACE_REPO_NAME = "market";
public static final String AXONIVY_MARKETPLACE_PATH = "market";
public static final String PRODUCT_JSON_FILE_PATH_FORMAT = "%s/product.json";
public static final String GITHUB_PROVIDER_NAME = "GitHub";
public static final String GITHUB_GET_ACCESS_TOKEN_URL = "https://github.com/login/oauth/access_token";
public static final String README_FILE_LOCALE_REGEX = "_(..)";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,18 @@ public class MavenConstants {
public static final String DEFAULT_IVY_MAVEN_BASE_URL = "https://maven.axonivy.com";
public static final String ARTIFACT_FILE_NAME_FORMAT = "%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 MAIN_VERSION_REGEX = "\\.";
public static final String LATEST_VERSION_TAG = "latest";
public static final String LATEST_RELEASE_TAG = "release";
public static final String DATE_TIME_FORMAT = "yyyyMMddHHmmss";
public static final String VERSION_TAG = "version";
public static final String LAST_UPDATED_TAG = "lastUpdated";
public static final String METADATA_URL_POSTFIX = "maven-metadata.xml";
public static final String SNAPSHOT_LAST_UPDATED_TAG = "timestamp";
public static final String SNAPSHOT_LAST_UPDATED_DATE_TIME_FORMAT = "yyyyMMdd.HHmmss";
public static final String VALUE_TAG = "value";
public static final String DEFAULT_PRODUCT_FOLDER_TYPE = "zip";


private MavenConstants() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ 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";
public static final String DEFAULT_COST_VALUE = "Free";
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ public class MongoDBConstants {
public static final String PRODUCT_ID = "productId";
public static final String DESIGNER_VERSION = "designerVersion";
public static final String TAG = "tag";

public static final String PROJECT_KEY = "$project";
public static final String RELEASED_VERSIONS = "releasedVersions";
public static final String ARTIFACTS = "artifacts";
public static final String MAVEN_VERSIONS = "mavenVersions";
private MongoDBConstants() {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class RequestMappingConstants {
public static final String FEEDBACK = API + "/feedback";
public static final String IMAGE = API + "/image";
public static final String SYNC = "sync";
public static final String SYNC_PRODUCT_VERSION = SYNC + "/product-version";
public static final String SWAGGER_URL = "/swagger-ui/index.html";
public static final String GIT_HUB_LOGIN = "/github/login";
public static final String AUTH = "/auth";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
import com.axonivy.market.model.Message;
import com.axonivy.market.model.ProductCustomSortRequest;
import com.axonivy.market.model.ProductModel;
import com.axonivy.market.service.MetadataService;
import com.axonivy.market.service.ProductService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.time.StopWatch;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.data.domain.Page;
Expand All @@ -40,20 +42,14 @@

@RestController
@RequestMapping(PRODUCT)
@AllArgsConstructor
@Tag(name = "Product Controller", description = "API collection to get and search products")
public class ProductController {
private final ProductService productService;
private final GitHubService gitHubService;
private final ProductModelAssembler assembler;
private final PagedResourcesAssembler<Product> pagedResourcesAssembler;

public ProductController(ProductService productService, GitHubService gitHubService, ProductModelAssembler assembler,
PagedResourcesAssembler<Product> pagedResourcesAssembler) {
this.productService = productService;
this.gitHubService = gitHubService;
this.assembler = assembler;
this.pagedResourcesAssembler = pagedResourcesAssembler;
}
private final MetadataService metadataService;

@GetMapping()
@Operation(summary = "Retrieve a paginated list of all products, optionally filtered by type, keyword, and language",
Expand Down Expand Up @@ -113,6 +109,25 @@ public ResponseEntity<Message> syncProducts(@RequestHeader(value = AUTHORIZATION
return new ResponseEntity<>(message, HttpStatus.OK);
}

@PutMapping(SYNC_PRODUCT_VERSION)
@Operation(hidden = true)
public ResponseEntity<Message> syncProductVersions(@RequestHeader(value = AUTHORIZATION) String authorizationHeader) {
String token = getBearerToken(authorizationHeader);
gitHubService.validateUserOrganization(token, GitHubConstants.AXONIVY_MARKET_ORGANIZATION_NAME);
int nonSyncResult = metadataService.syncAllProductsMetadata();
var message = new Message();
HttpStatus statusCode = HttpStatus.OK;
if(nonSyncResult == 1) {
message.setHelpCode(ErrorCode.SUCCESSFUL.getCode());
message.setHelpText(ErrorCode.SUCCESSFUL.getHelpText());
} else {
statusCode = HttpStatus.INTERNAL_SERVER_ERROR;
message.setHelpCode(ErrorCode.MAVEN_VERSION_SYNC_FAILED.getCode());
message.setMessageDetails(ErrorCode.MAVEN_VERSION_SYNC_FAILED.getHelpText());
}
return new ResponseEntity<>(message, statusCode);
}

@PostMapping(CUSTOM_SORT)
@Operation(hidden = true)
public ResponseEntity<Message> createCustomSortProducts(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public ResponseEntity<List<MavenArtifactVersionModel>> findProductVersionsById(
"Ivy designer")
public ResponseEntity<Map<String, Object>> findProductJsonContent(@PathVariable(ID) String productId,
@PathVariable(VERSION) String version) {
Map<String, Object> productJsonContent = versionService.getProductJsonContentByIdAndVersion(productId, version);
Map<String, Object> productJsonContent = versionService.getProductJsonContentByIdAndTag(productId, version);
return new ResponseEntity<>(productJsonContent, HttpStatus.OK);
}

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

import com.axonivy.market.model.MavenArtifactModel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Builder;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.data.annotation.Id;
Expand All @@ -12,23 +13,39 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

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

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Document(MAVEN_ARTIFACT_VERSION)
public class MavenArtifactVersion implements Serializable {
@Serial
private static final long serialVersionUID = -6492612804634492078L;

@Id
private String productId;
private Map<String, List<MavenArtifactModel>> productArtifactWithVersionReleased = new HashMap<>();
private Map<String, List<MavenArtifactModel>> productArtifactsByVersion;
private Map<String, List<MavenArtifactModel>> additionalArtifactsByVersion;

public String getProductId() {
return productId;
}

public MavenArtifactVersion(String productId) {
this.productId = productId;
public Map<String, List<MavenArtifactModel>> getProductArtifactsByVersion() {
if (Objects.isNull(productArtifactsByVersion)) {
this.productArtifactsByVersion = new HashMap<>();
}
return this.productArtifactsByVersion;
}

public Map<String, List<MavenArtifactModel>> getAdditionalArtifactsByVersion() {
if (Objects.isNull(this.additionalArtifactsByVersion)) {
this.additionalArtifactsByVersion = new HashMap<>();
}
return this.additionalArtifactsByVersion;
}


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

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;

import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Objects;
import java.util.Set;

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


@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Document(METADATA)
public class Metadata implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
@Id
private String url;
private String productId;
private LocalDateTime lastUpdated;
private String artifactId;
private String groupId;
private String latest;
private String release;
private Set<String> versions;
private String repoUrl;
private String type;
private String name;
private boolean isProductArtifact;
private String snapshotVersionValue;

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Metadata that = (Metadata) o;
return Objects.equals(url, that.url);
}

@Override
public int hashCode() {
return Objects.hashCode(url);
}
}
Loading

0 comments on commit 735fb43

Please sign in to comment.