-
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.
feature/MARPP-759 open marketplace from within designer correct version
- Loading branch information
1 parent
2c25696
commit 1ed484a
Showing
34 changed files
with
816 additions
and
305 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
20 changes: 20 additions & 0 deletions
20
marketplace-service/src/main/java/com/axonivy/market/constants/MongoDBConstants.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,20 @@ | ||
package com.axonivy.market.constants; | ||
|
||
public class MongoDBConstants { | ||
private MongoDBConstants() { | ||
} | ||
|
||
public static final String ID ="_id"; | ||
public static final String ADD_FIELD ="$addFields"; | ||
public static final String PRODUCT_MODULE_CONTENTS ="productModuleContents"; | ||
public static final String PRODUCT_MODULE_CONTENT ="productModuleContent"; | ||
public static final String PRODUCT_MODULE_CONTENT_QUERY ="$productModuleContents"; | ||
public static final String FILTER ="$filter"; | ||
public static final String INPUT ="input"; | ||
public static final String AS ="as"; | ||
public static final String CONDITION ="cond"; | ||
public static final String EQUAL ="$eq"; | ||
public static final String PRODUCT_MODULE_CONTENT_TAG ="$$productModuleContent.tag"; | ||
public static final String PRODUCT_COLLECTION ="Product"; | ||
public static final String NEWEST_RELEASED_VERSION_QUERY = "$newestReleaseVersion"; | ||
} |
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
17 changes: 17 additions & 0 deletions
17
marketplace-service/src/main/java/com/axonivy/market/repository/CustomProductRepository.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.repository; | ||
|
||
import com.axonivy.market.entity.Product; | ||
|
||
import java.util.List; | ||
|
||
public interface CustomProductRepository { | ||
Product getProductByIdAndTag(String id, String tag); | ||
|
||
Product getProductById(String id); | ||
|
||
List<String> getReleasedVersionsById(String id); | ||
|
||
int updateInitialCount(String productId, int initialCount); | ||
|
||
int increaseInstallationCount(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
102 changes: 102 additions & 0 deletions
102
...service/src/main/java/com/axonivy/market/repository/impl/CustomProductRepositoryImpl.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,102 @@ | ||
package com.axonivy.market.repository.impl; | ||
|
||
import com.axonivy.market.constants.MongoDBConstants; | ||
import com.axonivy.market.entity.Product; | ||
import com.axonivy.market.repository.CustomProductRepository; | ||
import org.bson.Document; | ||
import org.springframework.data.mongodb.core.FindAndModifyOptions; | ||
import org.springframework.data.mongodb.core.MongoTemplate; | ||
import org.springframework.data.mongodb.core.aggregation.Aggregation; | ||
import org.springframework.data.mongodb.core.aggregation.AggregationOperation; | ||
import org.springframework.data.mongodb.core.aggregation.AggregationResults; | ||
import org.springframework.data.mongodb.core.query.Criteria; | ||
import org.springframework.data.mongodb.core.query.Query; | ||
import org.springframework.data.mongodb.core.query.Update; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
|
||
|
||
public class CustomProductRepositoryImpl implements CustomProductRepository { | ||
private final MongoTemplate mongoTemplate; | ||
|
||
public CustomProductRepositoryImpl(MongoTemplate mongoTemplate) { | ||
this.mongoTemplate = mongoTemplate; | ||
} | ||
|
||
private AggregationOperation createIdMatchOperation(String id) { | ||
return Aggregation.match(Criteria.where(MongoDBConstants.ID).is(id)); | ||
} | ||
|
||
public Document createDocumentFilterProductModuleContentByTag(String tag) { | ||
Document isProductModuleContentOfCurrentTag = new Document(MongoDBConstants.EQUAL, | ||
Arrays.asList(MongoDBConstants.PRODUCT_MODULE_CONTENT_TAG, tag)); | ||
Document loopOverProductModuleContents = new Document(MongoDBConstants.INPUT, | ||
MongoDBConstants.PRODUCT_MODULE_CONTENT_QUERY) | ||
.append(MongoDBConstants.AS, MongoDBConstants.PRODUCT_MODULE_CONTENT); | ||
return loopOverProductModuleContents.append(MongoDBConstants.CONDITION, isProductModuleContentOfCurrentTag); | ||
} | ||
|
||
private AggregationOperation createReturnFirstModuleContentOperation() { | ||
return context -> new Document(MongoDBConstants.ADD_FIELD, | ||
new Document(MongoDBConstants.PRODUCT_MODULE_CONTENTS, | ||
new Document(MongoDBConstants.FILTER, createDocumentFilterProductModuleContentByTag(MongoDBConstants.NEWEST_RELEASED_VERSION_QUERY)))); | ||
} | ||
|
||
private AggregationOperation createReturnFirstMatchTagModuleContentOperation(String tag) { | ||
return context -> new Document(MongoDBConstants.ADD_FIELD, | ||
new Document(MongoDBConstants.PRODUCT_MODULE_CONTENTS, | ||
new Document(MongoDBConstants.FILTER, createDocumentFilterProductModuleContentByTag(tag)))); | ||
} | ||
|
||
public Product queryProductByAggregation(Aggregation aggregation) { | ||
return Optional.of(mongoTemplate.aggregate(aggregation, MongoDBConstants.PRODUCT_COLLECTION, Product.class)) | ||
.map(AggregationResults::getUniqueMappedResult).orElse(null); | ||
} | ||
|
||
@Override | ||
public Product getProductByIdAndTag(String id, String tag) { | ||
// Create the aggregation pipeline | ||
Aggregation aggregation = Aggregation.newAggregation(createIdMatchOperation(id), createReturnFirstMatchTagModuleContentOperation(tag)); | ||
return queryProductByAggregation(aggregation); | ||
} | ||
|
||
@Override | ||
public Product getProductById(String id) { | ||
Aggregation aggregation = Aggregation.newAggregation(createIdMatchOperation(id), createReturnFirstModuleContentOperation()); | ||
return queryProductByAggregation(aggregation); | ||
} | ||
|
||
@Override | ||
public List<String> getReleasedVersionsById(String id) { | ||
Aggregation aggregation = Aggregation.newAggregation(createIdMatchOperation(id)); | ||
Product product = queryProductByAggregation(aggregation); | ||
if (Objects.isNull(product)) { | ||
return Collections.emptyList(); | ||
} | ||
return product.getReleasedVersions(); | ||
|
||
} | ||
|
||
public int updateInitialCount(String productId, int initialCount) { | ||
Update update = new Update().inc("InstallationCount", initialCount).set("SynchronizedInstallationCount", true); | ||
mongoTemplate.updateFirst(createQueryById(productId), update, Product.class); | ||
return Optional.ofNullable(getProductById(productId)).map(Product::getInstallationCount).orElse(0); | ||
} | ||
|
||
@Override | ||
public int increaseInstallationCount(String productId) { | ||
Update update = new Update().inc("InstallationCount", 1); | ||
// Find and modify the document, then return the updated InstallationCount field | ||
Product updatedProduct = mongoTemplate.findAndModify(createQueryById(productId), update, | ||
FindAndModifyOptions.options().returnNew(true), Product.class); | ||
return updatedProduct != null ? updatedProduct.getInstallationCount() : 0; | ||
} | ||
|
||
private Query createQueryById(String id) { | ||
return new Query(Criteria.where(MongoDBConstants.ID).is(id)); | ||
} | ||
} |
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
Oops, something went wrong.