Skip to content

Commit

Permalink
Fix the issue (#530) ProductSync's publish/unpublish build actions (#533
Browse files Browse the repository at this point in the history
)

* rename buildPublishUpdateAction to buildPublishOrUnpublishUpdateAction, and add unit test before adding functionality.
* add a fix to the buildPublishOrUnpublishUpdateAction and cover with new tests.
* Use boolean instead of Boolean.
* Prepare for the release 1.9.1, && add RELEASE_NOTES.md
  • Loading branch information
ahmetoz authored Aug 5, 2020
1 parent 729a053 commit 81618aa
Show file tree
Hide file tree
Showing 20 changed files with 464 additions and 61 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# commercetools sync
[![Build Status](https://travis-ci.org/commercetools/commercetools-sync-java.svg?branch=master)](https://travis-ci.org/commercetools/commercetools-sync-java)
[![codecov](https://codecov.io/gh/commercetools/commercetools-sync-java/branch/master/graph/badge.svg)](https://codecov.io/gh/commercetools/commercetools-sync-java)
[![Benchmarks 1.9.0](https://img.shields.io/badge/Benchmarks-1.9.0-orange.svg)](https://commercetools.github.io/commercetools-sync-java/benchmarks/)
[![Benchmarks 1.9.1](https://img.shields.io/badge/Benchmarks-1.9.1-orange.svg)](https://commercetools.github.io/commercetools-sync-java/benchmarks/)
[![Download](https://api.bintray.com/packages/commercetools/maven/commercetools-sync-java/images/download.svg) ](https://bintray.com/commercetools/maven/commercetools-sync-java/_latestVersion)
[![Javadoc](http://javadoc-badge.appspot.com/com.commercetools/commercetools-sync-java.svg?label=Javadoc)](https://commercetools.github.io/commercetools-sync-java/v/1.9.0/)
[![Javadoc](http://javadoc-badge.appspot.com/com.commercetools/commercetools-sync-java.svg?label=Javadoc)](https://commercetools.github.io/commercetools-sync-java/v/1.9.1/)
[![Known Vulnerabilities](https://snyk.io/test/github/commercetools/commercetools-sync-java/4b2e26113d591bda158217c5dc1cf80a88665646/badge.svg)](https://snyk.io/test/github/commercetools/commercetools-sync-java/4b2e26113d591bda158217c5dc1cf80a88665646)

More at https://commercetools.github.io/commercetools-sync-java
Expand Down Expand Up @@ -36,7 +36,7 @@ The library supports synchronising the following entities in commercetools
- [Ivy](#ivy)
- [Roadmap](#roadmap)
- [Release Notes](/docs/RELEASE_NOTES.md)
- [Javadoc](https://commercetools.github.io/commercetools-sync-java/v/1.9.0/)
- [Javadoc](https://commercetools.github.io/commercetools-sync-java/v/1.9.1/)
- [Benchmarks](https://commercetools.github.io/commercetools-sync-java/benchmarks/)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->
Expand Down Expand Up @@ -78,26 +78,26 @@ Here are the most popular ones:
<dependency>
<groupId>com.commercetools</groupId>
<artifactId>commercetools-sync-java</artifactId>
<version>1.9.0</version>
<version>1.9.1</version>
</dependency>
````

#### Gradle

````groovy
implementation 'com.commercetools:commercetools-sync-java:1.9.0'
implementation 'com.commercetools:commercetools-sync-java:1.9.1'
````

#### SBT

````
libraryDependencies += "com.commercetools" % "commercetools-sync-java" % "1.9.0"
libraryDependencies += "com.commercetools" % "commercetools-sync-java" % "1.9.1"
````

#### Ivy

````xml
<dependency org="com.commercetools" name="commercetools-sync-java" rev="1.9.0"/>
<dependency org="com.commercetools" name="commercetools-sync-java" rev="1.9.1"/>
````


Expand Down
12 changes: 6 additions & 6 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# commercetools sync
[![Build Status](https://travis-ci.org/commercetools/commercetools-sync-java.svg?branch=master)](https://travis-ci.org/commercetools/commercetools-sync-java)
[![codecov](https://codecov.io/gh/commercetools/commercetools-sync-java/branch/master/graph/badge.svg)](https://codecov.io/gh/commercetools/commercetools-sync-java)
[![Benchmarks 1.9.0](https://img.shields.io/badge/Benchmarks-1.9.0-orange.svg)](https://commercetools.github.io/commercetools-sync-java/benchmarks/)
[![Benchmarks 1.9.1](https://img.shields.io/badge/Benchmarks-1.9.1-orange.svg)](https://commercetools.github.io/commercetools-sync-java/benchmarks/)
[![Download](https://api.bintray.com/packages/commercetools/maven/commercetools-sync-java/images/download.svg) ](https://bintray.com/commercetools/maven/commercetools-sync-java/_latestVersion)
[![Javadoc](http://javadoc-badge.appspot.com/com.commercetools/commercetools-sync-java.svg?label=Javadoc)](https://commercetools.github.io/commercetools-sync-java/v/1.9.0/)
[![Javadoc](http://javadoc-badge.appspot.com/com.commercetools/commercetools-sync-java.svg?label=Javadoc)](https://commercetools.github.io/commercetools-sync-java/v/1.9.1/)
[![Known Vulnerabilities](https://snyk.io/test/github/commercetools/commercetools-sync-java/4b2e26113d591bda158217c5dc1cf80a88665646/badge.svg)](https://snyk.io/test/github/commercetools/commercetools-sync-java/4b2e26113d591bda158217c5dc1cf80a88665646)


Expand Down Expand Up @@ -55,18 +55,18 @@ Here are the most popular ones:
<dependency>
<groupId>com.commercetools</groupId>
<artifactId>commercetools-sync-java</artifactId>
<version>1.9.0</version>
<version>1.9.1</version>
</dependency>
````
#### Gradle
````groovy
implementation 'com.commercetools:commercetools-sync-java:1.9.0'
implementation 'com.commercetools:commercetools-sync-java:1.9.1'
````
#### SBT
````
libraryDependencies += "com.commercetools" % "commercetools-sync-java" % "1.9.0"
libraryDependencies += "com.commercetools" % "commercetools-sync-java" % "1.9.1"
````
#### Ivy
````xml
<dependency org="com.commercetools" name="commercetools-sync-java" rev="1.9.0"/>
<dependency org="com.commercetools" name="commercetools-sync-java" rev="1.9.1"/>
````
10 changes: 10 additions & 0 deletions docs/RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@
[Jar](https://bintray.com/commercetools/maven/commercetools-sync-java/1.9.0)
-->

### 1.9.1 - Aug 5, 2020
[Commits](https://github.com/commercetools/commercetools-sync-java/compare/1.9.0...1.9.1) |
[Javadoc](https://commercetools.github.io/commercetools-sync-java/v/1.9.1/) |
[Jar](https://bintray.com/commercetools/maven/commercetools-sync-java/1.9.1)

- 🐞 **Bug Fixes** (1)
- **Product Sync** - Fixed a bug in the `ProductSync` related to publish/unpublish of the product update actions,
when a new product draft has publish flag set to true and the existing product is published already then no publish action will be created
which was not correct [#530](https://github.com/commercetools/commercetools-sync-java/issues/530)

### 1.9.0 - July 27, 2020
[Commits](https://github.com/commercetools/commercetools-sync-java/compare/1.8.2...1.9.0) |
[Javadoc](https://commercetools.github.io/commercetools-sync-java/v/1.9.0/) |
Expand Down
2 changes: 1 addition & 1 deletion docs/usage/CART_DISCOUNT_SYNC.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Therefore, in order for the sync to resolve the actual ids of those references i
reference should return its `key`.

**Note**: When syncing from a source commercetools project, you can use this util which this library provides:
[`replaceCartDiscountsReferenceIdsWithKeys`](https://commercetools.github.io/commercetools-sync-java/v/1.9.0/com/commercetools/sync/cartdiscounts/utils/CartDiscountReferenceReplacementUtils.html#replaceCartDiscountsReferenceIdsWithKeys-java.util.List-)
[`replaceCartDiscountsReferenceIdsWithKeys`](https://commercetools.github.io/commercetools-sync-java/v/1.9.1/com/commercetools/sync/cartdiscounts/utils/CartDiscountReferenceReplacementUtils.html#replaceCartDiscountsReferenceIdsWithKeys-java.util.List-)
that replaces the references id fields with keys, in order to make them ready for reference resolution by the sync:
````java
// Puts the keys in the reference id fields to prepare for reference resolution
Expand Down
2 changes: 1 addition & 1 deletion docs/usage/CATEGORY_SYNC.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ otherwise they won't be matched.
reference would return its `key`.

**Note**: When syncing from a source commercetools project, you can use this util which this library provides:
[`replaceCategoriesReferenceIdsWithKeys`](https://commercetools.github.io/commercetools-sync-java/v/1.9.0/com/commercetools/sync/categories/utils/CategoryReferenceReplacementUtils.html#replaceCategoriesReferenceIdsWithKeys-java.util.List-)
[`replaceCategoriesReferenceIdsWithKeys`](https://commercetools.github.io/commercetools-sync-java/v/1.9.1/com/commercetools/sync/categories/utils/CategoryReferenceReplacementUtils.html#replaceCategoriesReferenceIdsWithKeys-java.util.List-)
that replaces the references id fields with keys, in order to make them ready for reference resolution by the sync:
````java
// Puts the keys in the reference id fields to prepare for reference resolution
Expand Down
2 changes: 1 addition & 1 deletion docs/usage/IMPORTANT_USAGE_TIPS.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ productSync.sync(batch1)
By design, scaling the sync process should **not** be done by executing the batches themselves in parallel. However, it can be done either by:

- Changing the number of [max parallel requests](https://github.com/commercetools/commercetools-sync-java/tree/master/src/main/java/com/commercetools/sync/commons/utils/ClientConfigurationUtils.java#L116) within the `sphereClient` configuration. It defines how many requests the client can execute in parallel.
- or changing the draft [batch size](https://commercetools.github.io/commercetools-sync-java/v/1.9.0/com/commercetools/sync/commons/BaseSyncOptionsBuilder.html#batchSize-int-). It defines how many drafts can one batch contain.
- or changing the draft [batch size](https://commercetools.github.io/commercetools-sync-java/v/1.9.1/com/commercetools/sync/commons/BaseSyncOptionsBuilder.html#batchSize-int-). It defines how many drafts can one batch contain.

The current overridable default [configuration](https://github.com/commercetools/commercetools-sync-java/tree/master/src/main/java/com/commercetools/sync/commons/utils/ClientConfigurationUtils.java#L45) of the `sphereClient`
is the recommended good balance for stability and performance for the sync process.
Expand Down
2 changes: 1 addition & 1 deletion docs/usage/INVENTORY_SYNC.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ against a [InventoryEntryDraft](https://docs.commercetools.com/http-api-projects
reference would return its `key`.

**Note**: When syncing from a source commercetools project, you can use this util which this library provides:
[`replaceInventoriesReferenceIdsWithKeys`](https://commercetools.github.io/commercetools-sync-java/v/1.9.0/com/commercetools/sync/inventories/utils/InventoryReferenceReplacementUtils.html#replaceInventoriesReferenceIdsWithKeys-java.util.List-)
[`replaceInventoriesReferenceIdsWithKeys`](https://commercetools.github.io/commercetools-sync-java/v/1.9.1/com/commercetools/sync/inventories/utils/InventoryReferenceReplacementUtils.html#replaceInventoriesReferenceIdsWithKeys-java.util.List-)
that replaces the references id fields with keys, in order to make them ready for reference resolution by the sync:
````java
// Puts the keys in the reference id fields to prepare for reference resolution
Expand Down
2 changes: 1 addition & 1 deletion docs/usage/PRODUCT_SYNC.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ order for the sync to resolve the actual ids of those references, those `key`s h
reference would return its `key`.

**Note**: When syncing from a source commercetools project, you can use this util which this library provides:
[`replaceProductsReferenceIdsWithKeys`](https://commercetools.github.io/commercetools-sync-java/v/1.9.0/com/commercetools/sync/products/utils/ProductReferenceReplacementUtils.html#replaceProductsReferenceIdsWithKeys-java.util.List-)
[`replaceProductsReferenceIdsWithKeys`](https://commercetools.github.io/commercetools-sync-java/v/1.9.1/com/commercetools/sync/products/utils/ProductReferenceReplacementUtils.html#replaceProductsReferenceIdsWithKeys-java.util.List-)
that replaces the references id fields with keys, in order to make them ready for reference resolution by the sync:
````java
// Puts the keys in the reference id fields to prepare for reference resolution
Expand Down
2 changes: 1 addition & 1 deletion docs/usage/PRODUCT_TYPE_SYNC.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ references, those `key`s have to be supplied in the following way:
reference would return its `key`.

**Note**: When syncing from a source commercetools project, you can use this util which this library provides:
[`replaceProductTypesReferenceIdsWithKeys`](https://commercetools.github.io/commercetools-sync-java/v/1.9.0/com/commercetools/sync/producttypes/utils/ProductTypeReferenceReplacementUtils.html#replaceProductTypesReferenceIdsWithKeys-java.util.List-)
[`replaceProductTypesReferenceIdsWithKeys`](https://commercetools.github.io/commercetools-sync-java/v/1.9.1/com/commercetools/sync/producttypes/utils/ProductTypeReferenceReplacementUtils.html#replaceProductTypesReferenceIdsWithKeys-java.util.List-)
that replaces the references id fields with keys, in order to make them ready for reference resolution by the sync:
````java
// Puts the keys in the reference id fields to prepare for reference resolution
Expand Down
18 changes: 9 additions & 9 deletions docs/usage/QUICK_START.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,35 @@
<dependency>
<groupId>com.commercetools.sdk.jvm.core</groupId>
<artifactId>commercetools-models</artifactId>
<version>1.51.0</version>
<version>1.52.0</version>
</dependency>
<dependency>
<groupId>com.commercetools.sdk.jvm.core</groupId>
<artifactId>commercetools-java-client</artifactId>
<version>1.51.0</version>
<version>1.52.0</version>
</dependency>
<dependency>
<groupId>com.commercetools.sdk.jvm.core</groupId>
<artifactId>commercetools-convenience</artifactId>
<version>1.51.0</version>
<version>1.52.0</version>
</dependency>

<!-- Add commercetools-sync-java dependency. -->
<dependency>
<groupId>com.commercetools</groupId>
<artifactId>commercetools-sync-java</artifactId>
<version>1.9.0</version>
<version>1.9.1</version>
</dependency>
````
- For Gradle users:
````groovy
// Add commercetools-jvm-sdk dependencies.
implementation 'com.commercetools.sdk.jvm.core:commercetools-models:1.51.0'
implementation 'com.commercetools.sdk.jvm.core:commercetools-java-client:1.51.0'
implementation 'com.commercetools.sdk.jvm.core:commercetools-convenience:1.51.0'
implementation 'com.commercetools.sdk.jvm.core:commercetools-models:1.52.0'
implementation 'com.commercetools.sdk.jvm.core:commercetools-java-client:1.52.0'
implementation 'com.commercetools.sdk.jvm.core:commercetools-convenience:1.52.0'
// Add commercetools-sync-java dependency.
implementation 'com.commercetools:commercetools-sync-java:1.9.0'
implementation 'com.commercetools:commercetools-sync-java:1.9.1'
````

### 2. Setup Syncing Options
Expand Down Expand Up @@ -86,4 +86,4 @@ implementation 'com.commercetools:commercetools-sync-java:1.9.0'
*[Product Sync](PRODUCT_SYNC.md), [ProductType Sync](PRODUCT_TYPE_SYNC.md),
[Category Sync](CATEGORY_SYNC.md), [Inventory Sync](INVENTORY_SYNC.md),
[Type Sync](TYPE_SYNC.md), [CartDiscount Sync](CART_DISCOUNT_SYNC.md),
[TaxCategory Sync](/docs/usage/TAX_CATEGORY_SYNC.md)*
[TaxCategory Sync](/docs/usage/TAX_CATEGORY_SYNC.md), [State Sync](/docs/usage/STATE_SYNC.md)*
2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ nav:
- Advanced:
- Sync Options: usage/SYNC_OPTIONS.md
- Usage Tips: usage/IMPORTANT_USAGE_TIPS.md
- Javadoc: https://commercetools.github.io/commercetools-sync-java/v/1.9.0/
- Javadoc: https://commercetools.github.io/commercetools-sync-java/v/1.9.1/
- Release notes: RELEASE_NOTES.md
- Roadmap: https://github.com/commercetools/commercetools-sync-java/milestones
- Issues: https://github.com/commercetools/commercetools-sync-java/issues
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.sphere.sdk.products.attributes.Attribute;
import io.sphere.sdk.products.attributes.AttributeDraft;
import io.sphere.sdk.products.commands.ProductCreateCommand;
import io.sphere.sdk.products.commands.updateactions.Publish;
import io.sphere.sdk.products.commands.updateactions.SetAttribute;
import io.sphere.sdk.products.commands.updateactions.SetAttributeInAllVariants;
import io.sphere.sdk.products.queries.ProductByKeyGet;
Expand Down Expand Up @@ -249,6 +250,41 @@ void sync_withChangesOnlyAndUnPublish_ShouldUpdateProducts() {
assertThat(warningCallBackMessages).isEmpty();
}

@Test
void sync_withUpdatedDraftAndPublishFlagSetToTrue_ShouldPublishProductEvenItWasPublishedBefore() {
final ProductDraft publishedProductDraft = createProductDraft(PRODUCT_KEY_1_RESOURCE_PATH,
targetProductType.toReference(), targetTaxCategory.toReference(), targetProductState.toReference(),
targetCategoryReferencesWithIds, createRandomCategoryOrderHints(targetCategoryReferencesWithIds));
CTP_TARGET_CLIENT.execute(ProductCreateCommand.of(publishedProductDraft)).toCompletableFuture().join();

// new product draft has a publish flag set to true and the existing product is published already
final ProductDraft newProductDraft = createProductDraftBuilder(PRODUCT_KEY_1_CHANGED_RESOURCE_PATH,
sourceProductType.toReference())
.taxCategory(sourceTaxCategory)
.state(sourceProductState)
.categories(sourceCategoryReferencesWithIds)
.categoryOrderHints(createRandomCategoryOrderHints(sourceCategoryReferencesWithIds))
.publish(true)
.build();

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

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

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

final ProductSyncStatistics syncStatistics = productSync.sync(productDrafts).toCompletableFuture().join();

assertThat(syncStatistics).hasValues(1, 0, 1, 0);
assertThat(errorCallBackMessages).isEmpty();
assertThat(errorCallBackExceptions).isEmpty();
assertThat(warningCallBackMessages).isEmpty();

// last action is publish
assertThat(updateActions.get(updateActions.size() - 1)).isEqualTo(Publish.of());
}

@Test
void sync_withPriceReferences_ShouldUpdateProducts() {
final ProductDraft existingProductDraft = createProductDraft(PRODUCT_KEY_1_WITH_PRICES_RESOURCE_PATH,
Expand Down Expand Up @@ -409,7 +445,8 @@ void sync_withProductTypeReference_ShouldUpdateProducts() {

assertThat(updateActions).containsExactlyInAnyOrder(
SetAttributeInAllVariants.of(targetProductRefAttr.getName(), targetProductRefAttr.getValue(), true),
SetAttributeInAllVariants.of(targetProductSetRefAttr.getName(), targetProductSetRefAttr.getValue(), true)
SetAttributeInAllVariants.of(targetProductSetRefAttr.getName(), targetProductSetRefAttr.getValue(), true),
Publish.of()
);
}

Expand Down Expand Up @@ -476,7 +513,8 @@ void sync_withChangedAttributes_ShouldUpdateProducts() {
SetAttributeInAllVariants.ofUnsetAttribute("verpackung", true),
SetAttributeInAllVariants.ofUnsetAttribute("anlieferung", true),
SetAttributeInAllVariants.ofUnsetAttribute("zubereitung", true),
SetAttribute.ofUnsetAttribute(1, "localisedText", true)
SetAttribute.ofUnsetAttribute(1, "localisedText", true),
Publish.of()
);
}

Expand Down Expand Up @@ -580,9 +618,9 @@ void sync_withEmptySetAttribute_ShouldCreateProductWithAnEmptySetAttribute() {
assertThat(errorCallBackMessages).isEmpty();
assertThat(errorCallBackExceptions).isEmpty();
assertThat(warningCallBackMessages).isEmpty();
assertThat(updateActions)
.containsExactly(SetAttributeInAllVariants
.of(productSetRefAttr.getName(), JsonNodeFactory.instance.arrayNode(), true));
assertThat(updateActions).containsExactly(
SetAttributeInAllVariants.of(productSetRefAttr.getName(), JsonNodeFactory.instance.arrayNode(), true),
Publish.of());

final Product targetProduct = CTP_TARGET_CLIENT.execute(ProductByKeyGet.of(sourceProductDraft.getKey()))
.toCompletableFuture()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,6 @@ void sync_withRemovedVariants_shouldNotRemoveVariants() {

assertThat(productOptional).isNotEmpty();
final Product fetchedProduct = productOptional.get();
assertThat(fetchedProduct.getMasterData().getCurrent().getVariants()).hasSize(1);
assertThat(fetchedProduct.getMasterData().getCurrent().getVariants()).hasSize(2);
}
}
Loading

0 comments on commit 81618aa

Please sign in to comment.