Skip to content

Commit 4403280

Browse files
Merge pull request #296 from commercetools/286-add-product-type-sync
286 Add product type sync
2 parents 1c181f9 + 3b5b517 commit 4403280

28 files changed

Lines changed: 1752 additions & 275 deletions

.travis.yml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,14 @@ cache:
3535
- $HOME/.gradle/caches/
3636
- $HOME/.gradle/wrapper/
3737
notifications:
38-
hipchat:
38+
slack:
3939
template:
40-
- '<b><a href="https://github.com/commercetools/commercetools-sync-java">%{repository}</a></b>
41-
#<a href="%{build_url}">%{build_number}</a>
42-
<br>(%{branch} - <a href="%{compare_url}">%{commit}</a> : %{author}): <b>%{message}</b>
43-
<br><b>Build duration:</b> %{duration}.'
44-
format: html
40+
- '<https://github.com/commercetools/commercetools-sync-java|%{repository}>#<%{build_url}|%{build_number}>'
41+
- '(%{branch} - <%{compare_url}|%{commit}> : %{author}): %{message}'
42+
- 'Build duration:'
43+
- '%{duration}.'
4544
on_pull_requests: false
4645
on_success: change
4746
on_failure: always
4847
rooms:
49-
secure: GamqCH6vg3VJJ8XypH+QvDtlfK8H3z+jhNswp4G1l4TLkkDIBwEC5Iu8GwQm3TjrgrNYGGNAtgcFrDNOJzDdQtsrYv7NyvJnHXzznX4kzjrIa8o+NmYpxw07s7g/2kzcRTzvOC7KvGz++a0BDMLa2Di/0UVM/Q12BFli0JuDxoVEzcD7ubqcv2MjEIjJcDRf7wrx4QPMcTZIvPPBC6Z/h7lU0WnQHeEj5qb3Uim4Z0qdzRgjxSM++37cCsiFxcV85ff0e9BmTeV2sdmS/GmCTY8bJ/FwH1ZuLUhbvwlOikHMJqvVxkeqeDto0p/sECn0tMkdS3dwx/T8L9G4YUHlL4N46khnNLZYISqUk36ncW+lGxe5sQU+kRL9Yv0Lk5BIB3vw00XMpIoKz+lsN7mgkTCyfeMM5+jgFk7gEnR/PtVulO2XIj1xwskip+EnyEZR7G+qzeGGPSMTJs2LzoEWYKwCh2aAQjYOLX4H3Gt6mhHkB4qIR51m2PINQYhQE/WXKGnJ4c+wOHavRo7foSYyWnB7CnyNkZZofqYqlTCQkIumkJ3vTGQmu+rkRSJ+NXoY6h1w0Bzz6GktCVofWd3Yg6h3eZ3Ge2HV73VCsyuPn72BZ4d+8/zpm6cGvLEJ6UnSbzDUrVHybaaAXaJcWYvKL6yVsWjXRR93EVKEp4ajdMs=
48+
secure: diL83Fqrx+Eyxd7ViNbmxHH+TO8BT1jqdVqcAVAJxRlr4ka+dG3CLaGvgK26/0cb/mj576eWIxmUFhOct+x4WziVl9EFxIP1aEQUxSMIBE9x/G3tFEfNlwDr9RlxqBbTKyuk4gQ6aZtS6eIqa7Zuz3uRfdQkUXTYe3CTR2Y3jTGBdJpwaZkGj1goGVkQb2YY1IT1YR6c5Mh7ac1g+xA3ES8fn6jEHwAQCjw+1Heo0A4PMLVFDZ+ySKS7U1trvpu+4o1uwv9Xf30czsSgcFa64fUw7rP8SrzaI68wvy4aqx1gPH3BdQdHY0uduywT8pUAaE+ZoZ6Mn80J/IuYQlsr7zrFjdAPHEOiKFFJrT+eEtMv/f6iQ6rsBhzwjca+Ah3SVHbrzYGNdWSwrpbN+uPbyVuXMjym+q/i6lvDpzgl1rEov4RJGFGsLZs06KqJ2Ql47qcMOB8zg4lGnqg6A7i0GkvF5Ftc//0BliMVvO0zpZW6wDVromNIqJmIKLgHZS9fb4NNwHiEHwA17zyrOucvCLXYgvSR+mcluBDfluRbQbyPUdevSkI11Uevfj5WWdfOBHGqVOq5kIwsG0pHKGcTfqtDYPaoP4TorKLEIFm8Ce8Ame77A8f/BB7gZaNuttPU937mXRLqTQXheHVwtYra9uKAmT3+NzhisMyTgS4IyOQ=

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Currently this library supports synchronising
4343
- [Categories](/docs/usage/CATEGORY_SYNC.md)
4444
- [Products](/docs/usage/PRODUCT_SYNC.md) (_Beta_: Not recommended for production use yet.)
4545
- [InventoryEntries](/docs/usage/INVENTORY_SYNC.md) (_Beta_: Not recommended for production use yet.)
46+
- [ProductTypes](/docs/usage/PRODUCT_TYPE_SYNC.md) (_Beta_: Not recommended for production use yet.)
4647

4748
### Prerequisites
4849

docs/RELEASE_NOTES.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,27 @@
5757
[Jar](https://bintray.com/commercetools/maven/commercetools-sync-java/v1.0.0-M14)
5858
-->
5959

60-
### v1.0.0-M13 - Jul 26, 2018
60+
### v1.0.0-M13 - Sept 4, 2018
6161
[Commits](https://github.com/commercetools/commercetools-sync-java/compare/v1.0.0-M12...v1.0.0-M13) |
6262
[Javadoc](https://commercetools.github.io/commercetools-sync-java/v/v1.0.0-M13/) |
6363
[Jar](https://bintray.com/commercetools/maven/commercetools-sync-java/v1.0.0-M13)
6464

65-
**New Features** (6)
65+
**New Features** (15)
66+
- **ProductType Sync** - Support for syncing productTypes. [#286](https://github.com/commercetools/commercetools-sync-java/issues/286) For more info how to use it please refer to [ProductType usage doc](/docs/usage/PRODUCT_TYPE_SYNC.md).
6667
- **Product Sync** - Support for syncing product prices. [#101](https://github.com/commercetools/commercetools-sync-java/issues/101)
6768
- **Product Sync** - `ProductSyncUtils#buildActions` now also calculates variants' all price update actions needed. [#101](https://github.com/commercetools/commercetools-sync-java/issues/101)
6869
- **Product Sync** - `ProductUpdateActionUtils#buildVariantsUpdateActions` now also calculates variants' all price update actions needed. [#101](https://github.com/commercetools/commercetools-sync-java/issues/101)
6970
- **Product Sync** - Introduced new update action build utility for building all needed update actions between two variants' prices `ProductVariantUpdateActionUtils#buildProductVariantPricesUpdateActions`. [#101](https://github.com/commercetools/commercetools-sync-java/issues/101)
7071
- **ProductSync** - `PriceReferenceResolver` now resolves prices' CustomerGroup references on prices. [#101](https://github.com/commercetools/commercetools-sync-java/issues/101)
7172
- **InventoryEntry Sync** - `InventoryReferenceReplacementUtils#replaceInventoriesReferenceIdsWithKeys` now supports replacing channel reference ids with keys. [#101](https://github.com/commercetools/commercetools-sync-java/issues/101)
73+
- **ProductType Sync** - Exposed `ProductTypeSyncUtils#buildActions` which calculates all needed update actions after comparing a `ProductType` and a `ProductTypeDraft`. [#286](https://github.com/commercetools/commercetools-sync-java/issues/286)
74+
- **ProductType Sync** - Exposed `ProductTypeUpdateActionUtils` which contains utils for calculating needed update actions after comparing individual fields of a `ProductType` and a `ProductTypeDraft`. [#286](https://github.com/commercetools/commercetools-sync-java/issues/286)
75+
- **ProductType Sync** - Exposed `ProductTypeUpdateAttributeDefinitionActionUtils` which contains utils for calculating needed update actions after comparing a list of `AttributeDefinition`s and a list of `AttributeDefinitionDraft`s. [#286](https://github.com/commercetools/commercetools-sync-java/issues/286)
76+
- **ProductType Sync** - Exposed `ProductTypeUpdateLocalizedEnumActionUtils` which contains utils for calculating needed update actions after comparing two lists of `LocalizedEnumValue`s. [#286](https://github.com/commercetools/commercetools-sync-java/issues/286)
77+
- **ProductType Sync** - Exposed `ProductTypeUpdatePlainEnumActionUtils` which contains utils for calculating needed update actions after comparing two lists of `EnumValue`s. [#286](https://github.com/commercetools/commercetools-sync-java/issues/286)
78+
- **ProductType Sync** - Exposed `AttributeDefinitionUpdateActionUtils` which contains utils for calculating needed update actions after comparing an `AttributeDefinition` and an `AttributeDefinitionDraft`. [#286](https://github.com/commercetools/commercetools-sync-java/issues/286)
79+
- **ProductType Sync** - Exposed `LocalizedEnumUpdateActionsUtils` which contains utils for calculating needed update actions after comparing two `LocalizedEnumValue`s. [#286](https://github.com/commercetools/commercetools-sync-java/issues/286)
80+
- **ProductType Sync** - Exposed `PlainEnumUpdateActionsUtils` which contains utils for calculating needed update actions after comparing two `EnumValue`s. [#286](https://github.com/commercetools/commercetools-sync-java/issues/286)
7281

7382
**Enhancements** (4)
7483
- **Commons** - Bumped gradle to version [gradle-4.9](https://docs.gradle.org/4.9/release-notes.html).

docs/usage/PRODUCT_TYPE_SYNC.md

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# commercetools product type sync
2+
3+
Utility which provides API for building CTP product type update actions and product type synchronisation.
4+
5+
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
6+
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
7+
8+
9+
- [Usage](#usage)
10+
- [Sync list of product type drafts](#sync-list-of-product-type-drafts)
11+
- [Prerequisites](#prerequisites)
12+
- [Running the sync](#running-the-sync)
13+
- [Build all update actions](#build-all-update-actions)
14+
- [Build particular update action(s)](#build-particular-update-actions)
15+
- [Caveats](#caveats)
16+
17+
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
18+
19+
## Usage
20+
21+
### Sync list of product type drafts
22+
23+
#### Prerequisites
24+
1. The sync expects a list of non-null `ProductTypeDrafts` objects that have their `key` fields set to match the
25+
product types from the source to the target. Also the target project is expected to have the `key` fields set, otherwise they won't be
26+
matched.
27+
2. It is an important responsibility of the user of the library to instantiate a `sphereClient` that has the following properties:
28+
- Limits the amount of concurrent requests done to CTP. This can be done by decorating the `sphereClient` with
29+
[QueueSphereClientDecorator](http://commercetools.github.io/commercetools-jvm-sdk/apidocs/io/sphere/sdk/client/QueueSphereClientDecorator.html)
30+
- Retries on 5xx errors with a retry strategy. This can be achieved by decorating the `sphereClient` with the
31+
[RetrySphereClientDecorator](http://commercetools.github.io/commercetools-jvm-sdk/apidocs/io/sphere/sdk/client/RetrySphereClientDecorator.html)
32+
33+
You can use the same client instantiating used in the integration tests for this library found
34+
[here](/src/main/java/com/commercetools/sync/commons/utils/ClientConfigurationUtils.java#L45).
35+
36+
4. After the `sphereClient` is setup, a `ProductTypeSyncOptions` should be be built as follows:
37+
````java
38+
// instantiating a ProductTypeSyncOptions
39+
final ProductTypeSyncOptions productTypeSyncOptions = ProductTypeSyncOptionsBuilder.of(sphereClient).build();
40+
````
41+
42+
The options can be used to provide additional optional configuration for the sync as well:
43+
- `errorCallBack`
44+
a callback that is called whenever an event occurs during the sync process that represents an error. Currently, these
45+
events.
46+
47+
- `warningCallBack`
48+
a callback that is called whenever an event occurs during the sync process that represents a warning. Currently, these
49+
events.
50+
51+
- `beforeUpdateCallback`
52+
a filter function which can be applied on a generated list of update actions. It allows the user to intercept product type
53+
update and modify (add/remove) update actions just before they are send to CTP API.
54+
55+
- `beforeCreateCallback`
56+
a filter function which can be applied on a product type draft before a request to create it on CTP is issued. It allows the
57+
user to intercept product type create requests modify the draft before the create request is sent to CTP API.
58+
59+
- `allowUuid`
60+
a flag, if set to `true`, enables the user to use keys with UUID format for references. By default, it is set to `false`.
61+
62+
Example of options usage, that sets the error and warning callbacks to output the message to the log error and warning
63+
streams, would look as follows:
64+
```java
65+
final Logger logger = LoggerFactory.getLogger(MySync.class);
66+
final ProductTypeSyncOptions productTypeSyncOptions = ProductTypeSyncOptionsBuilder.of(sphereClient)
67+
.errorCallBack(logger::error)
68+
.warningCallBack(logger::warn)
69+
.build();
70+
```
71+
72+
73+
#### Running the sync
74+
After all the aforementioned points in the previous section have been fulfilled, to run the sync:
75+
````java
76+
// instantiating a product type sync
77+
final ProductTypeSync productTypeSync = new ProductTypeSync(productTypeSyncOptions);
78+
79+
// execute the sync on your list of product types
80+
CompletionStage<ProductTypeSyncStatistics> syncStatisticsStage = productTypeSync.sync(productTypeDrafts);
81+
````
82+
The result of the completing the `syncStatisticsStage` in the previous code snippet contains a `ProductTypeSyncStatistics`
83+
which contains all the stats of the sync process; which includes a report message, the total number of updated, created,
84+
failed, processed product types and the processing time of the last sync batch in different time units and in a
85+
human readable format.
86+
87+
````java
88+
final ProductTypeSyncStatistics stats = syncStatisticsStage.toCompletebleFuture().join();
89+
stats.getReportMessage();
90+
/*"Summary: 2000 products types were processed in total (1000 created, 995 updated, 5 failed to sync)."*/
91+
````
92+
93+
__Note__ The statistics object contains the processing time of the last batch only. This is due to two reasons:
94+
1. The sync processing time should not take into account the time between supplying batches to the sync.
95+
2. It is not not known by the sync which batch is going to be the last one supplied.
96+
97+
More examples of how to use the sync can be found [here](/src/integration-test/java/com/commercetools/sync/integration/producttypes/ProductTypeSyncIT.java).
98+
99+
### Build all update actions
100+
101+
A utility method provided by the library to compare a ProductType with a new ProductTypeDraft and results in a list of product type update actions.
102+
```java
103+
List<UpdateAction<ProductType>> updateActions = ProductTypeSyncUtils.buildActions(productType, productTypeDraft, productTypeSyncOptions);
104+
```
105+
106+
### Build particular update action(s)
107+
108+
Utility methods provided by the library to compare the specific fields of a ProductType and a new ProductTypeDraft, and in turn builds
109+
the update action. One example is the `buildChangeNameUpdateAction` which compares names:
110+
````java
111+
Optional<UpdateAction<ProductType>> updateAction = ProductTypeUpdateActionUtils.buildChangeNameAction(oldProductType, productTypeDraft);
112+
````
113+
More examples of those utils for different fields can be found [here](/src/test/java/com/commercetools/sync/producttypes/utils/ProductTypeUpdateActionUtilsTest.java).
114+
115+
116+
## Caveats
117+
118+
1. Product types are either created or updated. Currently the tool does not support product type deletion.
119+
2. Syncing product types with an attribute of type [NestedType](https://docs.commercetools.com/http-api-projects-productTypes.html#nestedtype) is not supported yet.

0 commit comments

Comments
 (0)