From e87836b0895c28fca815d5663d5819e9b476e073 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=E1=BA=A7n=20V=C4=A9nh=20Thi=E1=BB=87n=20Ph=C3=BAc?= Date: Fri, 13 Sep 2024 08:18:03 +0700 Subject: [PATCH] MARP-1058 Remove unused imports --- .../ProductDetailModelAssembler.java | 42 +++++------- .../com/axonivy/market/entity/Product.java | 29 ++++---- .../market/factory/ProductFactory.java | 36 +++++----- .../axonivy/market/service/ImageService.java | 6 +- .../com/axonivy/market/util/ImageUtils.java | 14 ++-- .../GHAxonIvyProductRepoServiceImplTest.java | 66 +++++++++---------- .../service/impl/ImageServiceImplTest.java | 37 ++++------- .../axonivy/market/util/ImageUtilsTest.java | 9 ++- 8 files changed, 111 insertions(+), 128 deletions(-) diff --git a/marketplace-service/src/main/java/com/axonivy/market/assembler/ProductDetailModelAssembler.java b/marketplace-service/src/main/java/com/axonivy/market/assembler/ProductDetailModelAssembler.java index 8ef8df9ef..5509717c4 100644 --- a/marketplace-service/src/main/java/com/axonivy/market/assembler/ProductDetailModelAssembler.java +++ b/marketplace-service/src/main/java/com/axonivy/market/assembler/ProductDetailModelAssembler.java @@ -1,30 +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.entity.ProductModuleContent; -import com.axonivy.market.model.ProductDetailModel; -import com.axonivy.market.util.ImageUtils; -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 java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -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 { private final ProductModelAssembler productModelAssembler; @@ -55,17 +49,17 @@ private ProductDetailModel createModel(Product product, String version, String r 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(); + Link link = linkTo(methodOn(ProductDetailsController.class).findProductJsonContent(productId, bestMatchVersion)) + .withSelfRel(); model.setMetaProductJsonUrl(link.getHref()); } selfLinkWithTag = switch (requestPath) { - case RequestMappingConstants.BEST_MATCH_BY_ID_AND_VERSION -> - methodOn(ProductDetailsController.class).findBestMatchProductDetailsByVersion(productId, version); - case RequestMappingConstants.BY_ID_AND_VERSION -> - methodOn(ProductDetailsController.class).findProductDetailsByVersion(productId, version); - default -> methodOn(ProductDetailsController.class).findProductDetails(productId); + case RequestMappingConstants.BEST_MATCH_BY_ID_AND_VERSION -> + methodOn(ProductDetailsController.class).findBestMatchProductDetailsByVersion(productId, version); + case RequestMappingConstants.BY_ID_AND_VERSION -> + methodOn(ProductDetailsController.class).findProductDetailsByVersion(productId, version); + default -> methodOn(ProductDetailsController.class).findProductDetails(productId); }; model.add(linkTo(selfLinkWithTag).withSelfRel()); diff --git a/marketplace-service/src/main/java/com/axonivy/market/entity/Product.java b/marketplace-service/src/main/java/com/axonivy/market/entity/Product.java index 26c5579f2..2210ee24e 100644 --- a/marketplace-service/src/main/java/com/axonivy/market/entity/Product.java +++ b/marketplace-service/src/main/java/com/axonivy/market/entity/Product.java @@ -1,18 +1,6 @@ package com.axonivy.market.entity; -import com.axonivy.market.github.model.MavenArtifact; -import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import org.apache.commons.lang3.builder.EqualsBuilder; -import org.apache.commons.lang3.builder.HashCodeBuilder; -import org.springframework.data.annotation.Id; -import org.springframework.data.annotation.Transient; -import org.springframework.data.mongodb.core.mapping.DBRef; -import org.springframework.data.mongodb.core.mapping.Document; +import static com.axonivy.market.constants.EntityConstants.PRODUCT; import java.io.Serial; import java.io.Serializable; @@ -20,7 +8,20 @@ import java.util.List; import java.util.Map; -import static com.axonivy.market.constants.EntityConstants.PRODUCT; +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; +import org.springframework.data.annotation.Id; +import org.springframework.data.annotation.Transient; +import org.springframework.data.mongodb.core.mapping.Document; + +import com.axonivy.market.github.model.MavenArtifact; +import com.fasterxml.jackson.annotation.JsonProperty; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; @Getter @Setter diff --git a/marketplace-service/src/main/java/com/axonivy/market/factory/ProductFactory.java b/marketplace-service/src/main/java/com/axonivy/market/factory/ProductFactory.java index 3d320a390..5bac416d1 100644 --- a/marketplace-service/src/main/java/com/axonivy/market/factory/ProductFactory.java +++ b/marketplace-service/src/main/java/com/axonivy/market/factory/ProductFactory.java @@ -1,17 +1,10 @@ package com.axonivy.market.factory; -import com.axonivy.market.entity.Product; -import com.axonivy.market.github.model.Meta; -import com.axonivy.market.github.util.GitHubUtils; -import com.axonivy.market.model.DisplayValue; -import com.fasterxml.jackson.databind.ObjectMapper; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; -import lombok.extern.log4j.Log4j2; -import org.apache.commons.lang3.BooleanUtils; -import org.apache.commons.lang3.StringUtils; -import org.kohsuke.github.GHContent; -import org.springframework.util.CollectionUtils; +import static com.axonivy.market.constants.CommonConstants.SLASH; +import static com.axonivy.market.constants.MetaConstants.DEFAULT_VENDOR_NAME; +import static com.axonivy.market.constants.MetaConstants.DEFAULT_VENDOR_URL; +import static com.axonivy.market.constants.MetaConstants.META_FILE; +import static org.apache.commons.lang3.StringUtils.EMPTY; import java.io.IOException; import java.util.ArrayList; @@ -19,12 +12,19 @@ import java.util.List; import java.util.Map; -import static com.axonivy.market.constants.CommonConstants.LOGO_FILE; -import static com.axonivy.market.constants.CommonConstants.SLASH; -import static com.axonivy.market.constants.MetaConstants.DEFAULT_VENDOR_NAME; -import static com.axonivy.market.constants.MetaConstants.DEFAULT_VENDOR_URL; -import static com.axonivy.market.constants.MetaConstants.META_FILE; -import static org.apache.commons.lang3.StringUtils.EMPTY; +import org.apache.commons.lang3.BooleanUtils; +import org.apache.commons.lang3.StringUtils; +import org.kohsuke.github.GHContent; +import org.springframework.util.CollectionUtils; + +import com.axonivy.market.entity.Product; +import com.axonivy.market.github.model.Meta; +import com.axonivy.market.model.DisplayValue; +import com.fasterxml.jackson.databind.ObjectMapper; + +import lombok.AccessLevel; +import lombok.NoArgsConstructor; +import lombok.extern.log4j.Log4j2; @Log4j2 @NoArgsConstructor(access = AccessLevel.PRIVATE) diff --git a/marketplace-service/src/main/java/com/axonivy/market/service/ImageService.java b/marketplace-service/src/main/java/com/axonivy/market/service/ImageService.java index 06e1dcc9c..626950bc7 100644 --- a/marketplace-service/src/main/java/com/axonivy/market/service/ImageService.java +++ b/marketplace-service/src/main/java/com/axonivy/market/service/ImageService.java @@ -1,11 +1,11 @@ package com.axonivy.market.service; -import com.axonivy.market.entity.Image; -import com.axonivy.market.entity.Product; -import com.axonivy.market.entity.ProductModuleContent; import org.bson.types.Binary; import org.kohsuke.github.GHContent; +import com.axonivy.market.entity.Image; +import com.axonivy.market.entity.Product; + public interface ImageService { Binary getBinaryImage(GHContent ghContent); diff --git a/marketplace-service/src/main/java/com/axonivy/market/util/ImageUtils.java b/marketplace-service/src/main/java/com/axonivy/market/util/ImageUtils.java index 7c46a1c3d..5f746c07f 100644 --- a/marketplace-service/src/main/java/com/axonivy/market/util/ImageUtils.java +++ b/marketplace-service/src/main/java/com/axonivy/market/util/ImageUtils.java @@ -1,19 +1,19 @@ package com.axonivy.market.util; -import com.axonivy.market.controller.ProductDetailsController; -import com.axonivy.market.entity.ProductModuleContent; -import org.apache.commons.lang3.ObjectUtils; -import org.springframework.hateoas.Link; +import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo; +import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn; import java.util.ArrayList; import java.util.List; import java.util.Map; -import java.util.Optional; import java.util.regex.Matcher; import java.util.regex.Pattern; -import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo; -import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn; +import org.apache.commons.lang3.ObjectUtils; +import org.springframework.hateoas.Link; + +import com.axonivy.market.controller.ProductDetailsController; +import com.axonivy.market.entity.ProductModuleContent; public class ImageUtils { public static ProductModuleContent mappingImageForProductModuleContent(ProductModuleContent productModuleContent) { diff --git a/marketplace-service/src/test/java/com/axonivy/market/service/impl/GHAxonIvyProductRepoServiceImplTest.java b/marketplace-service/src/test/java/com/axonivy/market/service/impl/GHAxonIvyProductRepoServiceImplTest.java index 72e25b660..3cf328570 100644 --- a/marketplace-service/src/test/java/com/axonivy/market/service/impl/GHAxonIvyProductRepoServiceImplTest.java +++ b/marketplace-service/src/test/java/com/axonivy/market/service/impl/GHAxonIvyProductRepoServiceImplTest.java @@ -1,19 +1,25 @@ package com.axonivy.market.service.impl; -import com.axonivy.market.constants.CommonConstants; -import com.axonivy.market.constants.ProductJsonConstants; -import com.axonivy.market.constants.ReadmeConstants; -import com.axonivy.market.entity.Image; -import com.axonivy.market.entity.Product; -import com.axonivy.market.entity.ProductJsonContent; -import com.axonivy.market.enums.Language; -import com.axonivy.market.github.model.MavenArtifact; -import com.axonivy.market.github.service.GitHubService; -import com.axonivy.market.github.service.impl.GHAxonIvyProductRepoServiceImpl; -import com.axonivy.market.repository.ProductJsonContentRepository; -import com.axonivy.market.service.ImageService; -import com.fasterxml.jackson.databind.JsonNode; -import org.bson.types.Binary; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.reset; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -29,25 +35,19 @@ import org.mockito.Spy; import org.mockito.junit.jupiter.MockitoExtension; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertSame; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.reset; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import com.axonivy.market.constants.CommonConstants; +import com.axonivy.market.constants.ProductJsonConstants; +import com.axonivy.market.constants.ReadmeConstants; +import com.axonivy.market.entity.Image; +import com.axonivy.market.entity.Product; +import com.axonivy.market.entity.ProductJsonContent; +import com.axonivy.market.enums.Language; +import com.axonivy.market.github.model.MavenArtifact; +import com.axonivy.market.github.service.GitHubService; +import com.axonivy.market.github.service.impl.GHAxonIvyProductRepoServiceImpl; +import com.axonivy.market.repository.ProductJsonContentRepository; +import com.axonivy.market.service.ImageService; +import com.fasterxml.jackson.databind.JsonNode; @ExtendWith(MockitoExtension.class) class GHAxonIvyProductRepoServiceImplTest { diff --git a/marketplace-service/src/test/java/com/axonivy/market/service/impl/ImageServiceImplTest.java b/marketplace-service/src/test/java/com/axonivy/market/service/impl/ImageServiceImplTest.java index dfd87a7b4..e4c7b886e 100644 --- a/marketplace-service/src/test/java/com/axonivy/market/service/impl/ImageServiceImplTest.java +++ b/marketplace-service/src/test/java/com/axonivy/market/service/impl/ImageServiceImplTest.java @@ -1,9 +1,15 @@ package com.axonivy.market.service.impl; -import com.axonivy.market.constants.CommonConstants; -import com.axonivy.market.entity.Image; -import com.axonivy.market.entity.Product; -import com.axonivy.market.repository.ImageRepository; +import static com.axonivy.market.constants.CommonConstants.SLASH; +import static com.axonivy.market.constants.MetaConstants.META_FILE; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.io.IOException; +import java.io.InputStream; + import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.kohsuke.github.GHContent; @@ -11,28 +17,11 @@ import org.mockito.Captor; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; -import org.springframework.data.domain.Pageable; -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import static com.axonivy.market.constants.CommonConstants.SLASH; -import static com.axonivy.market.constants.MetaConstants.META_FILE; -import static com.axonivy.market.enums.DocumentField.SHORT_DESCRIPTIONS; -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyLong; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import com.axonivy.market.entity.Image; +import com.axonivy.market.entity.Product; +import com.axonivy.market.repository.ImageRepository; @ExtendWith(MockitoExtension.class) public class ImageServiceImplTest { diff --git a/marketplace-service/src/test/java/com/axonivy/market/util/ImageUtilsTest.java b/marketplace-service/src/test/java/com/axonivy/market/util/ImageUtilsTest.java index afa582028..d0369015b 100644 --- a/marketplace-service/src/test/java/com/axonivy/market/util/ImageUtilsTest.java +++ b/marketplace-service/src/test/java/com/axonivy/market/util/ImageUtilsTest.java @@ -1,15 +1,14 @@ package com.axonivy.market.util; -import com.axonivy.market.entity.ProductModuleContent; -import com.axonivy.market.github.util.GitHubUtils; -import org.apache.commons.lang3.StringUtils; +import java.util.HashMap; +import java.util.Map; + import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.junit.jupiter.MockitoExtension; -import java.util.HashMap; -import java.util.Map; +import com.axonivy.market.entity.ProductModuleContent; @ExtendWith(MockitoExtension.class) public class ImageUtilsTest {