-
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.
MARP-612 Storing number of downloads version (#128)
- Loading branch information
1 parent
a1e6514
commit 38f7e68
Showing
25 changed files
with
360 additions
and
42 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
38 changes: 38 additions & 0 deletions
38
...ce/src/main/java/com/axonivy/market/controller/ProductDesignerInstallationController.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,38 @@ | ||
package com.axonivy.market.controller; | ||
|
||
import com.axonivy.market.model.DesignerInstallation; | ||
import com.axonivy.market.service.ProductDesignerInstallationService; | ||
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.tags.Tag; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.List; | ||
|
||
import static com.axonivy.market.constants.RequestMappingConstants.DESIGNER_INSTALLATION_BY_PRODUCT_ID; | ||
import static com.axonivy.market.constants.RequestMappingConstants.PRODUCT_DESIGNER_INSTALLATION; | ||
import static com.axonivy.market.constants.RequestParamConstants.PRODUCT_ID; | ||
|
||
@RestController | ||
@RequestMapping(PRODUCT_DESIGNER_INSTALLATION) | ||
@Tag(name = "Product Designer Installation Controllers", description = "API collection to get designer installation count.") | ||
public class ProductDesignerInstallationController { | ||
private final ProductDesignerInstallationService productDesignerInstallationService; | ||
|
||
public ProductDesignerInstallationController(ProductDesignerInstallationService productDesignerInstallationService) { | ||
this.productDesignerInstallationService = productDesignerInstallationService; | ||
} | ||
|
||
@GetMapping(DESIGNER_INSTALLATION_BY_PRODUCT_ID) | ||
@Operation(summary = "Get designer installation count by product id.", description = "get designer installation count by product id") | ||
public ResponseEntity<List<DesignerInstallation>> getProductDesignerInstallationByProductId(@PathVariable(PRODUCT_ID) @Parameter(description = "Product id (from meta.json)", example = "adobe-acrobat-connector", in = ParameterIn.PATH) String productId) { | ||
List<DesignerInstallation> models = productDesignerInstallationService.findByProductId(productId); | ||
return new ResponseEntity<>(models, HttpStatus.OK); | ||
} | ||
} |
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
42 changes: 42 additions & 0 deletions
42
marketplace-service/src/main/java/com/axonivy/market/entity/ProductDesignerInstallation.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,42 @@ | ||
package com.axonivy.market.entity; | ||
|
||
import lombok.*; | ||
import org.apache.commons.lang3.builder.EqualsBuilder; | ||
import org.apache.commons.lang3.builder.HashCodeBuilder; | ||
import org.springframework.data.annotation.Id; | ||
import org.springframework.data.mongodb.core.mapping.Document; | ||
|
||
import java.io.Serial; | ||
import java.io.Serializable; | ||
import java.util.Date; | ||
|
||
import static com.axonivy.market.constants.EntityConstants.PRODUCT_DESIGNER_INSTALLATION; | ||
|
||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder | ||
@Document(PRODUCT_DESIGNER_INSTALLATION) | ||
public class ProductDesignerInstallation implements Serializable { | ||
@Serial | ||
private static final long serialVersionUID = 1L; | ||
@Id | ||
private String id; | ||
private String productId; | ||
private String designerVersion; | ||
private int installationCount; | ||
|
||
@Override | ||
public int hashCode() { | ||
return new HashCodeBuilder().append(productId).hashCode(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (obj == null || this.getClass() != obj.getClass()) { | ||
return false; | ||
} | ||
return new EqualsBuilder().append(productId, ((ProductDesignerInstallation) obj).getProductId()).isEquals(); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
marketplace-service/src/main/java/com/axonivy/market/model/DesignerInstallation.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,17 @@ | ||
package com.axonivy.market.model; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class DesignerInstallation { | ||
@Schema(description = "Ivy designer version", example = "11.4.0") | ||
private String designerVersion; | ||
private int numberOfDownloads; | ||
} |
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
14 changes: 14 additions & 0 deletions
14
...ce/src/main/java/com/axonivy/market/repository/ProductDesignerInstallationRepository.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,14 @@ | ||
package com.axonivy.market.repository; | ||
|
||
import com.axonivy.market.entity.ProductDesignerInstallation; | ||
import org.springframework.data.domain.Sort; | ||
import org.springframework.data.mongodb.repository.MongoRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.List; | ||
|
||
@Repository | ||
public interface ProductDesignerInstallationRepository extends MongoRepository<ProductDesignerInstallation, String> { | ||
|
||
List<ProductDesignerInstallation> findByProductId(String productId, Sort sort); | ||
} |
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
9 changes: 9 additions & 0 deletions
9
...-service/src/main/java/com/axonivy/market/service/ProductDesignerInstallationService.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,9 @@ | ||
package com.axonivy.market.service; | ||
|
||
import com.axonivy.market.model.DesignerInstallation; | ||
|
||
import java.util.List; | ||
|
||
public interface ProductDesignerInstallationService { | ||
List<DesignerInstallation> findByProductId(String productId); | ||
} |
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
...src/main/java/com/axonivy/market/service/impl/ProductDesignerInstallationServiceImpl.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.service.impl; | ||
|
||
import com.axonivy.market.constants.MongoDBConstants; | ||
import com.axonivy.market.entity.ProductDesignerInstallation; | ||
import com.axonivy.market.model.DesignerInstallation; | ||
import com.axonivy.market.repository.ProductDesignerInstallationRepository; | ||
import com.axonivy.market.service.ProductDesignerInstallationService; | ||
import lombok.extern.log4j.Log4j2; | ||
import org.springframework.data.domain.Sort; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Log4j2 | ||
@Service | ||
public class ProductDesignerInstallationServiceImpl implements ProductDesignerInstallationService { | ||
private final ProductDesignerInstallationRepository productDesignerInstallationRepository; | ||
|
||
public ProductDesignerInstallationServiceImpl(ProductDesignerInstallationRepository productDesignerInstallationRepository) { | ||
this.productDesignerInstallationRepository = productDesignerInstallationRepository; | ||
} | ||
|
||
@Override | ||
public List<DesignerInstallation> findByProductId(String productId) { | ||
List<DesignerInstallation> designerInstallations = new ArrayList<>(); | ||
List<ProductDesignerInstallation> productDesignerInstallations = | ||
productDesignerInstallationRepository.findByProductId(productId, Sort.by(Sort.Direction.DESC, MongoDBConstants.DESIGNER_VERSION)); | ||
for (ProductDesignerInstallation productDesignerInstallation : productDesignerInstallations) { | ||
DesignerInstallation designerInstallation = new DesignerInstallation(productDesignerInstallation.getDesignerVersion(), productDesignerInstallation.getInstallationCount()); | ||
designerInstallations.add(designerInstallation); | ||
} | ||
return designerInstallations; | ||
} | ||
} |
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
39 changes: 39 additions & 0 deletions
39
...rc/test/java/com/axonivy/market/controller/ProductDesignerInstallationControllerTest.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,39 @@ | ||
package com.axonivy.market.controller; | ||
|
||
import com.axonivy.market.model.DesignerInstallation; | ||
import com.axonivy.market.service.ProductDesignerInstallationService; | ||
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; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class ProductDesignerInstallationControllerTest { | ||
public static final String DESIGNER_VERSION = "11.4.0"; | ||
|
||
@Mock | ||
ProductDesignerInstallationService productDesignerInstallationService; | ||
|
||
@InjectMocks | ||
private ProductDesignerInstallationController productDesignerInstallationController; | ||
|
||
@Test | ||
void testGetProductDesignerInstallationByProductId() { | ||
List<DesignerInstallation> models = List.of(new DesignerInstallation(DESIGNER_VERSION, 5)); | ||
Mockito.when(productDesignerInstallationService.findByProductId(Mockito.anyString())).thenReturn(models); | ||
ResponseEntity<List<DesignerInstallation>> result = productDesignerInstallationController.getProductDesignerInstallationByProductId("portal"); | ||
Assertions.assertEquals(HttpStatus.OK, result.getStatusCode()); | ||
Assertions.assertEquals(1, Objects.requireNonNull(result.getBody()).size()); | ||
Assertions.assertEquals(DESIGNER_VERSION, result.getBody().get(0).getDesignerVersion()); | ||
Assertions.assertEquals(5, result.getBody().get(0).getNumberOfDownloads()); | ||
Assertions.assertEquals(models, result.getBody()); | ||
} | ||
} |
Oops, something went wrong.