-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #275 from axonivy-market/develop
MARP-1867 Create Marketplace release 1.8.0
- Loading branch information
Showing
80 changed files
with
1,969 additions
and
297 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
marketplace-service/src/main/java/com/axonivy/market/config/LimitCallingConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package com.axonivy.market.config; | ||
|
||
import io.github.bucket4j.Bandwidth; | ||
import io.github.bucket4j.Bucket; | ||
import io.micrometer.common.util.StringUtils; | ||
import jakarta.servlet.FilterChain; | ||
import jakarta.servlet.ServletException; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import lombok.extern.log4j.Log4j2; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.filter.OncePerRequestFilter; | ||
|
||
import java.io.IOException; | ||
import java.time.Duration; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
@Log4j2 | ||
@Component | ||
public class LimitCallingConfig extends OncePerRequestFilter { | ||
private static final String REQUEST_HEADER = "X-Forwarded-For"; | ||
@Value("${market.allowed.click-capacity}") | ||
private int capacity; | ||
|
||
@Value("${market.limited.request-paths}") | ||
private List<String> requestPaths; | ||
private final Map<String, Bucket> buckets = new ConcurrentHashMap<>(); | ||
|
||
@Override | ||
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) | ||
throws ServletException, IOException { | ||
|
||
String clientIp = getClientIp(request); | ||
String apiPath = request.getRequestURI(); | ||
|
||
boolean isRequestPathMatched = requestPaths.stream().anyMatch(apiPath::contains); | ||
if (isRequestPathMatched) { | ||
Bucket bucket = buckets.computeIfAbsent(clientIp, this::createNewBucket); | ||
|
||
if (bucket.tryConsume(1)) { | ||
log.warn("Request allowed for IP: {}. Remaining tokens: {}", clientIp, bucket.getAvailableTokens()); | ||
filterChain.doFilter(request, response); | ||
} else { | ||
response.setStatus(HttpServletResponse.SC_BAD_GATEWAY); | ||
response.getWriter().write("Too many requests. Please try again later."); | ||
} | ||
} else { | ||
filterChain.doFilter(request, response); | ||
} | ||
} | ||
|
||
private Bucket createNewBucket(String clientIp) { | ||
Bandwidth limit = Bandwidth.builder() | ||
.capacity(capacity) | ||
.refillGreedy(capacity, Duration.ofMinutes(1)) | ||
.build(); | ||
return Bucket.builder().addLimit(limit).build(); | ||
} | ||
|
||
private String getClientIp(HttpServletRequest request) { | ||
String forwardedFor = request.getHeader(REQUEST_HEADER); | ||
if (StringUtils.isNotEmpty(forwardedFor)) { | ||
return forwardedFor.split(",")[0]; | ||
} | ||
return request.getRemoteAddr(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
marketplace-service/src/main/java/com/axonivy/market/constants/PreviewConstants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.axonivy.market.constants; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
|
||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class PreviewConstants { | ||
|
||
public static final String PREVIEW_DIR = "data/work/preview"; | ||
|
||
public static final String IMAGE_DOWNLOAD_URL = "%s/api/image/preview/%s"; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...etplace-service/src/main/java/com/axonivy/market/controller/ReleasePreviewController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.axonivy.market.controller; | ||
|
||
import com.axonivy.market.model.ReleasePreview; | ||
import com.axonivy.market.service.ReleasePreviewService; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.AllArgsConstructor; | ||
import lombok.extern.log4j.Log4j2; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
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.multipart.MultipartFile; | ||
import org.springframework.web.servlet.support.ServletUriComponentsBuilder; | ||
|
||
import static com.axonivy.market.constants.RequestMappingConstants.RELEASE_PREVIEW; | ||
|
||
@Log4j2 | ||
@RestController | ||
@RequestMapping(RELEASE_PREVIEW) | ||
@Tag(name = "Release Preview Controller", description = "API to extract zip file and return README data.") | ||
@AllArgsConstructor | ||
public class ReleasePreviewController { | ||
|
||
private final ReleasePreviewService previewService; | ||
|
||
@PostMapping | ||
@Operation(hidden = true) | ||
public ResponseEntity<Object> extractZipFile(@RequestParam(value = "file") MultipartFile file) { | ||
String baseUrl = ServletUriComponentsBuilder.fromCurrentContextPath().build().toUriString(); | ||
ReleasePreview preview = previewService.extract(file, baseUrl); | ||
if (preview == null) { | ||
return new ResponseEntity<>(HttpStatus.NO_CONTENT); | ||
} | ||
return ResponseEntity.ok(preview); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
marketplace-service/src/main/java/com/axonivy/market/model/ReleasePreview.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.axonivy.market.model; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.*; | ||
|
||
import java.util.Map; | ||
|
||
import static com.axonivy.market.util.ProductContentUtils.DESCRIPTION; | ||
import static com.axonivy.market.util.ProductContentUtils.DEMO; | ||
import static com.axonivy.market.util.ProductContentUtils.SETUP; | ||
import static com.axonivy.market.util.ProductContentUtils.replaceEmptyContentsWithEnContent; | ||
|
||
@Getter | ||
@Setter | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class ReleasePreview { | ||
|
||
@Schema(description = "Product detail description content ", | ||
example = "{ \"de\": \"E-Sign-Konnektor\", \"en\": \"E-sign connector\" }") | ||
private Map<String, String> description; | ||
@Schema(description = "Setup tab content", example = "{ \"de\": \"Setup\", \"en\": \"Setup\" ") | ||
private Map<String, String> setup; | ||
@Schema(description = "Demo tab content", example = "{ \"de\": \"Demo\", \"en\": \"Demo\" ") | ||
private Map<String, String> demo; | ||
|
||
public static ReleasePreview from(Map<String, Map<String, String>> moduleContents) { | ||
return ReleasePreview.builder().description(replaceEmptyContentsWithEnContent(moduleContents.get(DESCRIPTION))) | ||
.demo(replaceEmptyContentsWithEnContent(moduleContents.get(DEMO))) | ||
.setup(replaceEmptyContentsWithEnContent(moduleContents.get(SETUP))) | ||
.build(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 0 additions & 6 deletions
6
marketplace-service/src/main/java/com/axonivy/market/service/MetadataService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,8 @@ | ||
package com.axonivy.market.service; | ||
|
||
import com.axonivy.market.bo.Artifact; | ||
import com.axonivy.market.entity.Product; | ||
import java.util.List; | ||
|
||
public interface MetadataService { | ||
|
||
int syncAllProductsMetadata(); | ||
|
||
boolean syncProductMetadata(Product product); | ||
|
||
void updateArtifactAndMetadata(String productId , List<String> versions , List<Artifact> artifacts); | ||
} |
Oops, something went wrong.