Skip to content

Commit

Permalink
MARP-1075 - Release v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ntqdinh-axonivy authored Sep 16, 2024
2 parents 8fa00ac + efe494a commit 69fbfa1
Show file tree
Hide file tree
Showing 142 changed files with 3,301 additions and 761 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/service-ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ jobs:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_PROJECT_KEY : ${{ secrets.SONAR_PROJECT_KEY }}
steps:
- name: Remove unused sonar images
run: docker image prune -af
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
Expand Down
12 changes: 9 additions & 3 deletions .github/workflows/ui-ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ jobs:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

steps:
- name: Setup chrome
uses: browser-actions/setup-chrome@v1

- name: Execute Tests
run: |
cd ./marketplace-ui
Expand All @@ -65,3 +62,12 @@ jobs:
env:
SONAR_TOKEN: ${{ env.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ env.SONAR_HOST_URL }}

clean-up:
name: Remove unused docker images
needs: analysis
runs-on: self-hosted

steps:
- name: Remove unused sonar images
run: docker image prune -af
3 changes: 2 additions & 1 deletion marketplace-build/.env
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ MARKET_GITHUB_TOKEN=
MARKET_GITHUB_OAUTH_APP_CLIENT_ID=
MARKET_GITHUB_OAUTH_APP_CLIENT_SECRET=
MARKET_JWT_SECRET_KEY=
MARKET_CORS_ALLOWED_ORIGIN=*
MARKET_CORS_ALLOWED_ORIGIN=*
MARKET_MONGO_LOG_LEVEL=DEBUG
28 changes: 28 additions & 0 deletions marketplace-build/config/nginx/dev/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
events {}

http {
include /etc/nginx/mime.types;

server {
listen 80;
server_name marketplace;

root /usr/share/nginx/html;
index index.html;

location / {
try_files $uri $uri/ /index.html;
}

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-NginX-Proxy true;
proxy_pass http://service:8080/marketplace-service;
proxy_ssl_session_reuse off;
proxy_set_header Host $http_host;
proxy_cache_bypass $http_upgrade;
proxy_redirect off;
}
}
}
3 changes: 2 additions & 1 deletion marketplace-build/dev/.env
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ MARKET_GITHUB_TOKEN=
MARKET_GITHUB_OAUTH_APP_CLIENT_ID=
MARKET_GITHUB_OAUTH_APP_CLIENT_SECRET=
MARKET_JWT_SECRET_KEY=
MARKET_CORS_ALLOWED_ORIGIN=*
MARKET_CORS_ALLOWED_ORIGIN=*
MARKET_MONGO_LOG_LEVEL=DEBUG
5 changes: 3 additions & 2 deletions marketplace-build/dev/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ services:
- BUILD_ENV=${BUILD_ENV}
restart: always
volumes:
- ../../marketplace-build/config/nginx/nginx.conf:/etc/nginx/nginx.conf
- ../../marketplace-build/config/nginx/dev/nginx.conf:/etc/nginx/nginx.conf
ports:
- "4200:80"
depends_on:
Expand All @@ -22,7 +22,7 @@ services:
container_name: marketplace-service
restart: always
volumes:
- /home/axonivy/marketplace/data/market-installations.json:/home/data/market-installation.json
- /home/axonivy/marketplace/data/market-installations.json:/data/market-installation.json
environment:
- MONGODB_HOST=${SERVICE_MONGODB_HOST}
- MONGODB_DATABASE=${SERVICE_MONGODB_DATABASE}
Expand All @@ -34,6 +34,7 @@ services:
- MARKET_GITHUB_OAUTH_APP_CLIENT_SECRET=${MARKET_GITHUB_OAUTH_APP_CLIENT_SECRET}
- MARKET_JWT_SECRET_KEY=${MARKET_JWT_SECRET_KEY}
- MARKET_CORS_ALLOWED_ORIGIN=${MARKET_CORS_ALLOWED_ORIGIN}
- MARKET_MONGO_LOG_LEVEL=${MARKET_MONGO_LOG_LEVEL}
build:
context: ../../marketplace-service
dockerfile: Dockerfile
Expand Down
3 changes: 2 additions & 1 deletion marketplace-build/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ services:
container_name: marketplace-service
restart: always
volumes:
- /home/axonivy/marketplace/data/market-installations.json:/home/data/market-installation.json
- /home/axonivy/marketplace/data/market-installations.json:/data/market-installation.json
environment:
- MONGODB_HOST=${SERVICE_MONGODB_HOST}
- MONGODB_DATABASE=${SERVICE_MONGODB_DATABASE}
Expand All @@ -49,6 +49,7 @@ services:
- MARKET_GITHUB_OAUTH_APP_CLIENT_SECRET=${MARKET_GITHUB_OAUTH_APP_CLIENT_SECRET}
- MARKET_JWT_SECRET_KEY=${MARKET_JWT_SECRET_KEY}
- MARKET_CORS_ALLOWED_ORIGIN=${MARKET_CORS_ALLOWED_ORIGIN}
- MARKET_MONGO_LOG_LEVEL=${MARKET_MONGO_LOG_LEVEL}
build:
context: ../marketplace-service
dockerfile: Dockerfile
Expand Down
3 changes: 2 additions & 1 deletion marketplace-build/release/.env
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ MARKET_GITHUB_TOKEN=
MARKET_GITHUB_OAUTH_APP_CLIENT_ID=
MARKET_GITHUB_OAUTH_APP_CLIENT_SECRET=
MARKET_JWT_SECRET_KEY=
MARKET_CORS_ALLOWED_ORIGIN=*
MARKET_CORS_ALLOWED_ORIGIN=*
MARKET_MONGO_LOG_LEVEL=DEBUG
3 changes: 2 additions & 1 deletion marketplace-build/release/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ services:
expose:
- 8080
volumes:
- /home/axonivy/marketplace/data/market-installations.json:/home/data/market-installation.json
- /home/axonivy/marketplace/data/market-installations.json:/data/market-installation.json
environment:
- MONGODB_HOST=${SERVICE_MONGODB_HOST}
- MONGODB_DATABASE=${SERVICE_MONGODB_DATABASE}
Expand All @@ -41,5 +41,6 @@ services:
- MARKET_GITHUB_OAUTH_APP_CLIENT_SECRET=${MARKET_GITHUB_OAUTH_APP_CLIENT_SECRET}
- MARKET_JWT_SECRET_KEY=${MARKET_JWT_SECRET_KEY}
- MARKET_CORS_ALLOWED_ORIGIN=${MARKET_CORS_ALLOWED_ORIGIN}
- MARKET_MONGO_LOG_LEVEL=${MARKET_MONGO_LOG_LEVEL}
volumes:
mongodata:
1 change: 0 additions & 1 deletion marketplace-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
package com.axonivy.market.assembler;

import com.axonivy.market.constants.RequestMappingConstants;
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 static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn;

import java.util.Optional;

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;
import org.springframework.util.CollectionUtils;

import java.util.Optional;

import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn;
import com.axonivy.market.constants.RequestMappingConstants;
import com.axonivy.market.controller.ProductDetailsController;
import com.axonivy.market.entity.Product;
import com.axonivy.market.model.ProductDetailModel;
import com.axonivy.market.util.ImageUtils;
import com.axonivy.market.util.VersionUtils;

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

private final ProductModelAssembler productModelAssembler;
Expand Down Expand Up @@ -80,6 +79,7 @@ private void createDetailResource(ProductDetailModel model, Product product) {
model.setContactUs(product.getContactUs());
model.setCost(product.getCost());
model.setInstallationCount(product.getInstallationCount());
model.setProductModuleContent(product.getProductModuleContent());
model.setProductModuleContent(ImageUtils.mappingImageForProductModuleContent(product.getProductModuleContent()));
}

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

import com.axonivy.market.controller.ImageController;
import com.axonivy.market.controller.ProductDetailsController;
import com.axonivy.market.entity.Product;
import com.axonivy.market.model.ProductModel;
import org.springframework.hateoas.Link;
import org.springframework.hateoas.server.mvc.RepresentationModelAssemblerSupport;
import org.springframework.stereotype.Component;

Expand All @@ -29,7 +31,9 @@ public ProductModel createResource(ProductModel model, Product product) {
model.setShortDescriptions(product.getShortDescriptions());
model.setType(product.getType());
model.setTags(product.getTags());
model.setLogoUrl(product.getLogoUrl());

Link logoLink = linkTo(methodOn(ImageController.class).findImageById(product.getLogoId())).withSelfRel();
model.setLogoUrl(logoLink.getHref());
return model;
}

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

import com.axonivy.market.constants.CommonConstants;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.kohsuke.github.GHTag;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static com.axonivy.market.constants.CommonConstants.DASH_SEPARATOR;
import static com.axonivy.market.constants.MavenConstants.SNAPSHOT_VERSION;
import static org.apache.commons.lang3.StringUtils.EMPTY;

public class MavenVersionComparator {

private static final String MAIN_VERSION_REGEX = "\\.";
private static final int GREATER_THAN = 1;
private static final int EQUAL = 0;
private static final int LESS_THAN = -1;

private MavenVersionComparator() {
}

public static GHTag findHighestTag(List<GHTag> ghTags) {
if (CollectionUtils.isEmpty(ghTags)) {
return null;
}
String highestVersion = findHighestMavenVersion(ghTags.stream().map(GHTag::getName).toList());
return ghTags.stream().filter(tag -> tag.getName().equals(highestVersion)).findAny().orElse(null);
}

public static String findHighestMavenVersion(List<String> versions) {
if (CollectionUtils.isEmpty(versions)) {
return null;
}

String highestVersion = versions.get(0);
for (var version : versions) {
if (compare(version, highestVersion) > EQUAL) {
highestVersion = version;
}
}
return highestVersion;
}

private static int compare(String version, String otherVersion) {
version = stripLeadingChars(version);
otherVersion = stripLeadingChars(otherVersion);
String[] versionParts = createMainAndQualifierArray(version);
String[] otherVersionParts = createMainAndQualifierArray(otherVersion);

// Compare main version parts
int mainComparison = compareMainVersion(versionParts[0], otherVersionParts[0]);
if (mainComparison != EQUAL) {
return mainComparison;
}

// Compare qualifiers
String qualifier1 = getQualifierPart(versionParts);
String qualifier2 = getQualifierPart(otherVersionParts);
// Consider versions without a qualifier higher than those with qualifiers
if (qualifier1.isEmpty() && !qualifier2.isEmpty()) {
return GREATER_THAN;
}
if (!qualifier1.isEmpty() && qualifier2.isEmpty()) {
return LESS_THAN;
}
return compareQualifier(qualifier1, qualifier2);
}

private static String stripLeadingChars(String version) {
Pattern pattern = Pattern.compile(CommonConstants.DIGIT_REGEX);
Matcher matcher = pattern.matcher(version);
if (matcher.find()) {
return matcher.group(1);
}
return version;
}

private static int compareMainVersion(String mainVersion, String otherMainVersion) {
String[] parts1 = mainVersion.split(MAIN_VERSION_REGEX);
String[] parts2 = otherMainVersion.split(MAIN_VERSION_REGEX);

int length = Math.max(parts1.length, parts2.length);
for (int i = 0; i < length; i++) {
int num1 = parseToNumber(parts1, i);
int num2 = parseToNumber(parts2, i);
if (num1 != num2) {
return num1 - num2;
}
}
return EQUAL;
}

private static String getQualifierPart(String[] versionParts) {
return versionParts.length > 1 ? versionParts[1] : EMPTY;
}

private static String[] createMainAndQualifierArray(String version) {
return StringUtils.defaultIfBlank(version, EMPTY).split(DASH_SEPARATOR, 2);
}

private static int parseToNumber(String[] versionParts, int index) {
if (index < versionParts.length && NumberUtils.isDigits(versionParts[index])) {
return NumberUtils.toInt(versionParts[index]);
}
return 0;
}

private static int compareQualifier(String qualifier1, String qualifier2) {
if (SNAPSHOT_VERSION.equals(qualifier1) && !SNAPSHOT_VERSION.equals(qualifier2)) {
return LESS_THAN;
}
if (!SNAPSHOT_VERSION.equals(qualifier1) && SNAPSHOT_VERSION.equals(qualifier2)) {
return GREATER_THAN;
}
return qualifier1.compareTo(qualifier2);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.axonivy.market.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.AsyncConfigurer;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;

@Configuration
public class AsyncConfig implements AsyncConfigurer {

private static final String THREAD_NAME_PREFIX = "AC-Thread-";

@Override
public Executor getAsyncExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(5);
executor.setMaxPoolSize(10);
executor.setQueueCapacity(25);
executor.setThreadNamePrefix(THREAD_NAME_PREFIX);
executor.initialize();
return executor;
}
}
Loading

0 comments on commit 69fbfa1

Please sign in to comment.