Skip to content

Commit

Permalink
MARP-473 Reformat code
Browse files Browse the repository at this point in the history
  • Loading branch information
tvtphuc-axonivy committed Jul 16, 2024
1 parent ed4e4e5 commit 3bc1caf
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 61 deletions.
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
package com.axonivy.market.controller;

import com.axonivy.market.model.MavenArtifactVersionModel;
import com.axonivy.market.service.ProductService;
import com.axonivy.market.service.VersionService;
import io.swagger.v3.oas.annotations.Operation;
import static com.axonivy.market.constants.RequestMappingConstants.PRODUCT_DETAILS;

import java.util.List;

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.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 com.axonivy.market.assembler.ProductDetailModelAssembler;
import com.axonivy.market.model.MavenArtifactVersionModel;
import com.axonivy.market.model.ProductDetailModel;
import com.axonivy.market.service.ProductService;
import com.axonivy.market.service.VersionService;

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

import java.util.List;

import static com.axonivy.market.constants.RequestMappingConstants.PRODUCT_DETAILS;
import io.swagger.v3.oas.annotations.Operation;

@RestController
@RequestMapping(PRODUCT_DETAILS)
Expand All @@ -42,12 +42,13 @@ public ResponseEntity<ProductDetailModel> findProductDetailsByVersion(@PathVaria
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);
}
@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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,17 @@

import java.io.IOException;
import java.net.URL;

import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Random;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.lang3.BooleanUtils;

import java.util.*;

import com.axonivy.market.constants.CommonConstants;
import com.axonivy.market.github.service.GHAxonIvyProductRepoService;
import com.axonivy.market.github.util.GitHubUtils;
import com.axonivy.market.entity.ProductModuleContent;

import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.util.Strings;
import org.kohsuke.github.GHCommit;
Expand All @@ -40,24 +32,27 @@
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import com.axonivy.market.constants.CommonConstants;
import com.axonivy.market.constants.GitHubConstants;
import com.axonivy.market.entity.GitHubRepoMeta;
import com.axonivy.market.entity.Product;
import com.axonivy.market.entity.ProductModuleContent;
import com.axonivy.market.enums.FileType;
import com.axonivy.market.enums.SortOption;
import com.axonivy.market.enums.TypeOption;
import com.axonivy.market.factory.ProductFactory;
import com.axonivy.market.github.model.GitHubFile;
import com.axonivy.market.github.service.GHAxonIvyMarketRepoService;
import com.axonivy.market.entity.GitHubRepoMeta;
import com.axonivy.market.enums.TypeOption;
import com.axonivy.market.github.service.GHAxonIvyProductRepoService;
import com.axonivy.market.github.service.GitHubService;
import com.axonivy.market.github.util.GitHubUtils;
import com.axonivy.market.repository.GitHubRepoMetaRepository;
import com.axonivy.market.repository.ProductRepository;
import com.axonivy.market.service.ProductService;
import com.fasterxml.jackson.databind.ObjectMapper;

import lombok.extern.log4j.Log4j2;

import javax.swing.text.html.Option;

@Log4j2
@Service
public class ProductServiceImpl implements ProductService {
Expand Down Expand Up @@ -146,8 +141,8 @@ private void syncInstallationCountWithProduct(Product product) {
String installationCounts = Files.readString(Paths.get(installationCountPath));
Map<String, Integer> mapping = mapper.readValue(installationCounts, HashMap.class);
List<String> keyList = mapping.keySet().stream().toList();
int currentInstallationCount = keyList.contains(product.getId()) ?
mapping.get(product.getId()) : random.nextInt(20, 50);
int currentInstallationCount = keyList.contains(product.getId()) ? mapping.get(product.getId())
: random.nextInt(20, 50);
product.setInstallationCount(currentInstallationCount);
product.setSynchronizedInstallationCount(true);
log.info("synchronized installation count for product {} successfully", product.getId());
Expand Down Expand Up @@ -322,6 +317,7 @@ private void updateProductFromReleaseTags(Product product) {
}

// Cover 3 cases after removing non-numeric characters (8, 11.1 and 10.0.2)
@Override
public String getCompatibilityFromOldestTag(String oldestTag) {
if (!oldestTag.contains(CommonConstants.DOT_SEPARATOR)) {
return oldestTag + ".0+";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,30 @@
package com.axonivy.market.controller;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.when;

import com.axonivy.market.model.MavenArtifactVersionModel;
import com.axonivy.market.service.ProductService;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import java.util.List;
import java.util.Objects;

import com.axonivy.market.model.MavenArtifactVersionModel;
import com.axonivy.market.model.MultilingualismValue;
import com.axonivy.market.service.VersionService;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;

import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

import java.util.List;
import java.util.Objects;

import com.axonivy.market.assembler.ProductDetailModelAssembler;
import com.axonivy.market.entity.Product;
import com.axonivy.market.model.MavenArtifactVersionModel;
import com.axonivy.market.model.MultilingualismValue;
import com.axonivy.market.model.ProductDetailModel;
import com.axonivy.market.service.ProductService;
import com.axonivy.market.service.VersionService;

@ExtendWith(MockitoExtension.class)
class ProductDetailsControllerTest {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.axonivy.market.service;

import static com.axonivy.market.constants.CommonConstants.LOGO_FILE;
import static com.axonivy.market.constants.MetaConstants.META_FILE;
import static com.axonivy.market.constants.CommonConstants.SLASH;
import static com.axonivy.market.constants.MetaConstants.META_FILE;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand All @@ -26,22 +26,16 @@
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import static org.mockito.Mockito.*;

import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.util.stream.Collectors;

import com.axonivy.market.entity.ProductModuleContent;
import com.axonivy.market.github.service.GHAxonIvyProductRepoService;
import com.axonivy.market.model.MultilingualismValue;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.kohsuke.github.GHCommit;
import org.kohsuke.github.GHContent;
import org.kohsuke.github.*;
import org.kohsuke.github.GHRepository;
import org.kohsuke.github.GHTag;
import org.kohsuke.github.PagedIterable;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.InjectMocks;
Expand All @@ -59,13 +53,16 @@
import com.axonivy.market.constants.GitHubConstants;
import com.axonivy.market.entity.GitHubRepoMeta;
import com.axonivy.market.entity.Product;
import com.axonivy.market.entity.ProductModuleContent;
import com.axonivy.market.enums.FileStatus;
import com.axonivy.market.enums.FileType;
import com.axonivy.market.enums.SortOption;
import com.axonivy.market.enums.TypeOption;
import com.axonivy.market.github.model.GitHubFile;
import com.axonivy.market.github.service.GHAxonIvyMarketRepoService;
import com.axonivy.market.github.service.GHAxonIvyProductRepoService;
import com.axonivy.market.github.service.GitHubService;
import com.axonivy.market.model.MultilingualismValue;
import com.axonivy.market.repository.GitHubRepoMetaRepository;
import com.axonivy.market.repository.ProductRepository;
import com.axonivy.market.service.impl.ProductServiceImpl;
Expand Down Expand Up @@ -155,8 +152,8 @@ void testSyncInstallationCountWithProduct() throws Exception {
}

private Product mockProduct() {
return Product.builder().id("google-maps-connector").language("English")
.synchronizedInstallationCount(true).build();
return Product.builder().id("google-maps-connector").language("English").synchronizedInstallationCount(true)
.build();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
package com.axonivy.market.service;

import com.axonivy.market.schedulingtask.ScheduledTasks;
import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.verify;

import org.awaitility.Awaitility;
import org.awaitility.Durations;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.SpyBean;

import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.verify;
import com.axonivy.market.schedulingtask.ScheduledTasks;

@SpringBootTest(properties = {
"marketPlace-installation-url=D:/marketplace-installation.json"
})
@SpringBootTest(properties = { "marketPlace-installation-url=D:/marketplace-installation.json" })
class SchedulingTasksTest {

@SpyBean
Expand Down

0 comments on commit 3bc1caf

Please sign in to comment.