Skip to content

Commit

Permalink
#99: Refactor product query into own method.
Browse files Browse the repository at this point in the history
  • Loading branch information
heshamMassoud committed Sep 27, 2017
1 parent 784e395 commit 4aa6594
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,17 @@ static void deleteProductTypes(@Nonnull final SphereClient ctpClient) {
.toArray(new CompletableFuture[productTypeDeleteFutures.size()])))
.toCompletableFuture().join();
}

/**
* Builds the query for fetching products from the source CTP project with all the needed expansions.
* @return the query for fetching products from the source CTP project with all the needed expansions.
*/
public static ProductQuery getProductQuery() {
return ProductQuery.of().withLimit(SphereClientUtils.QUERY_MAX_LIMIT)
.withExpansionPaths(ProductExpansionModel::productType)
.plusExpansionPaths(productProductExpansionModel ->
productProductExpansionModel.masterData().staged().categories())
.plusExpansionPaths(channelExpansionModel ->
channelExpansionModel.masterData().staged().allVariants().prices().channel());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,7 @@ public void sync_withChangesOnly_ShouldUpdateProducts() {
sourceProductType.toReference(), sourceCategories, createRandomCategoryOrderHints(sourceCategories));
CTP_SOURCE_CLIENT.execute(ProductCreateCommand.of(newProductDraft)).toCompletableFuture().join();

final ProductQuery productQuery = ProductQuery.of().withLimit(SphereClientUtils.QUERY_MAX_LIMIT)
.withExpansionPaths(ProductExpansionModel::productType)
.plusExpansionPaths(categoryExpansionModel ->
categoryExpansionModel.masterData().staged().categories())
.plusExpansionPaths(channelExpansionModel ->
channelExpansionModel.masterData().staged().allVariants()
.prices().channel());

final List<Product> products = CTP_SOURCE_CLIENT.execute(productQuery)
final List<Product> products = CTP_SOURCE_CLIENT.execute(getProductQuery())
.toCompletableFuture().join().getResults();

final List<ProductDraft> productDrafts = replaceProductsReferenceIdsWithKeys(products);
Expand Down Expand Up @@ -159,13 +151,9 @@ public void sync_withChangesOnlyAndUnPublish_ShouldUpdateProducts() {

CTP_SOURCE_CLIENT.execute(ProductCreateCommand.of(newProductDraft)).toCompletableFuture().join();

final ProductQuery productQuery = ProductQuery.of().withLimit(SphereClientUtils.QUERY_MAX_LIMIT)
.withExpansionPaths(ProductExpansionModel::productType)
.plusExpansionPaths(productProductExpansionModel ->
productProductExpansionModel.masterData().staged()
.categories());
final List<Product> products = CTP_SOURCE_CLIENT.execute(getProductQuery())

final List<Product> products = CTP_SOURCE_CLIENT.execute(productQuery)
final List<Product> products = CTP_SOURCE_CLIENT.execute(getProductQuery())
.toCompletableFuture().join().getResults();

final List<ProductDraft> productDrafts = replaceProductsReferenceIdsWithKeys(products);
Expand Down

0 comments on commit 4aa6594

Please sign in to comment.