Skip to content

Commit 176af63

Browse files
Merge pull request #259 from commercetools/3-assets
3 assets
2 parents b31f79d + 56b700c commit 176af63

90 files changed

Lines changed: 5969 additions & 674 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@
66
# gradle specific
77
.gradle/
88
build/
9+
10+
# Benchmarks
11+
benchmarks.json

docs/RELEASE_NOTES.md

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
3434

3535

36+
- [v1.0.0-M11 - Mar 08, 2018](#v100-m11----mar-08-2018)
3637
- [v1.0.0-M10 - Feb 13, 2018](#v100-m10----feb-13-2018)
3738
- [v1.0.0-M9 - Jan 22, 2018](#v100-m9----jan-22-2018)
3839
- [v1.0.0-M8 - Dec 29, 2017](#v100-m8----dec-29-2017)
@@ -48,33 +49,55 @@
4849
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
4950

5051
<!--
51-
### v1.0.0-M11 - Mar 01, 2018
52+
### v1.0.0-M12 - Mar 30, 2018
53+
[Commits](https://github.com/commercetools/commercetools-sync-java/compare/v1.0.0-M11...v1.0.0-M12) |
54+
[Javadoc](https://commercetools.github.io/commercetools-sync-java/v/v1.0.0-M12/) |
55+
[Jar](https://bintray.com/commercetools/maven/commercetools-sync-java/v1.0.0-M12)
56+
-->
57+
58+
### v1.0.0-M11 - Mar 08, 2018
5259
[Commits](https://github.com/commercetools/commercetools-sync-java/compare/v1.0.0-M10...v1.0.0-M11) |
5360
[Javadoc](https://commercetools.github.io/commercetools-sync-java/v/v1.0.0-M11/) |
5461
[Jar](https://bintray.com/commercetools/maven/commercetools-sync-java/v1.0.0-M11)
5562

56-
**New Features** (4)
63+
**New Features** (19)
64+
- **Category Sync** - Support of categories' asset syncing. [#3](https://github.com/commercetools/commercetools-sync-java/issues/3)
65+
- **Product Sync** - Support of product variants' asset syncing. [#3](https://github.com/commercetools/commercetools-sync-java/issues/3)
66+
- **Category Sync** - CategorySyncUtils#buildActions now also calculates all asset update actions needed. [#3](https://github.com/commercetools/commercetools-sync-java/issues/3)
67+
- **Product Sync** - ProductSyncUtils#buildActions now also calculates variants' all asset update actions needed. [#3](https://github.com/commercetools/commercetools-sync-java/issues/3)
68+
- **Product Sync** - ProductUpdateActionUtils#buildVariantsUpdateActions now also calculates variants' all asset update actions needed. [#3](https://github.com/commercetools/commercetools-sync-java/issues/3)
69+
- **Product Sync** - Introduced the new ActionGroup: ASSETS which can be used in blacklisting/whitelisting assets syncing during the product sync. [#3](https://github.com/commercetools/commercetools-sync-java/issues/3)
70+
- **Category Sync** - Introduced new update action build utility for building all neeeded update actions between two categories' asstes ProductVariantUpdateActionUtils#buildProductVariantAssetsUpdateActions. [#3](https://github.com/commercetools/commercetools-sync-java/issues/3)
71+
- **Product Sync** - Introduced new update action build utility for building all neeeded update actions between two variants' asstes ProductVariantUpdateActionUtils#buildProductVariantAssetsUpdateActions. [#3](https://github.com/commercetools/commercetools-sync-java/issues/3)
72+
- **Category Sync** - Introduced new update action granular build utils for category asset fields in CategoryAssetUpdateActionUtils. [#3](https://github.com/commercetools/commercetools-sync-java/issues/3)
73+
- **Product Sync** - Introduced new update action granular build utils for product variant assets fields in ProductVariantAssetUpdateActionUtils. [#3](https://github.com/commercetools/commercetools-sync-java/issues/3)
5774
- **Commons** - Introduced `AssetReferenceResolver` which is a helper that can resolve all the references of an AssetDraft. [#3](https://github.com/commercetools/commercetools-sync-java/issues/3)
5875
- **Commons** - `VariantReferenceResolver` and `CategoryReferenceResolver` now also resolve all the containing AssetDrafts references. [#3](https://github.com/commercetools/commercetools-sync-java/issues/3)
5976
- **Commons** - Support for custom update actions calculation for secondary resources (e.g. prices, product assets and category assets). [#3](https://github.com/commercetools/commercetools-sync-java/issues/3)
77+
- **Product Sync** - ProductReferenceReplacementUtils#replaceProductsReferenceIdsWithKeys and VariantReferenceReplacementUtils#replaceVariantsReferenceIdsWithKeys now support replacing asset custom reference ids with keys. [#3](https://github.com/commercetools/commercetools-sync-java/issues/3)
78+
- **Category Sync** - CategoryReferenceReplacementUtils#replaceCategoriesReferenceIdsWithKeys now supports replacing asset custom reference ids with keys. [#3](https://github.com/commercetools/commercetools-sync-java/issues/3)
79+
- **Commons** - Introduced new SyncUtils#replaceAssetsReferenceIdsWithKeys which is a util that replaces the custom type ids with keys in a list of assets. [#3](https://github.com/commercetools/commercetools-sync-java/issues/3)
80+
- **Product Sync** - ProductReferenceReplacementUtils#buildProductQuery now expands custom types on assets. [#3](https://github.com/commercetools/commercetools-sync-java/issues/3)
81+
- **Category Sync** - CategoryReferenceReplacementUtils#buildCategoryQuery now expands custom types on assets. [#3](https://github.com/commercetools/commercetools-sync-java/issues/3)
6082
- **Commons** - Introduced new ResourceIdentifierUtils#toResourceIdentifierIfNotNull. [#262](https://github.com/commercetools/commercetools-sync-java/issues/262)
6183

62-
**Changes** (3)
84+
**Changes** (5)
6385
- **Commons** - `CustomUpdateActionUtils#buildCustomUpdateActions` is now
6486
`CustomUpdateActionUtils#buildPrimaryResourceCustomUpdateActions`. It now takes a new third parameter `customActionBuilder`
6587
which represents the concrete builder of custom update actions. For a list of concrete builder options check the
6688
implementors of the `GenericCustomActionBuilder` interface. [#3](https://github.com/commercetools/commercetools-sync-java/issues/3)
6789
- **Commons** - `CustomUpdateActionUtils#buildCustomUpdateActions` can now be used to build custom update actions
6890
for secondary resources (e.g. assets and prices). [#3](https://github.com/commercetools/commercetools-sync-java/issues/3)
6991
- **Commons** - New Custom Type Id is now validated against being empty/null. [#3](https://github.com/commercetools/commercetools-sync-java/issues/3)
92+
- **Product Sync** - ProductSyncUtils#buildCoreActions is now removed. ProductSyncUtils#buildActions should be used instead. [#3](https://github.com/commercetools/commercetools-sync-java/issues/3)
93+
- **Category Sync** - CategorySyncUtils#buildCoreActions is now removed. CategorySyncUtils#buildActions should be used instead. [#3](https://github.com/commercetools/commercetools-sync-java/issues/3)
7094

7195
**Enhancements** (1)
72-
- **Build Tools** - Bumped commercetools-jvm-sdk to version [1.29.0](http://commercetools.github.io/commercetools-jvm-sdk/apidocs/io/sphere/sdk/meta/ReleaseNotes.html#v1_29_0). [#262](https://github.com/commercetools/commercetools-sync-java/issues/262)
96+
- **Build Tools** - Bumped commercetools-jvm-sdk to version [1.30.0](http://commercetools.github.io/commercetools-jvm-sdk/apidocs/io/sphere/sdk/meta/ReleaseNotes.html#v1_30_0). [#262](https://github.com/commercetools/commercetools-sync-java/issues/262)
7397

7498
**Bug Fixes** (1)
7599
- **Build Tools** - Fixed bug where jar and Codecov were triggered on benchmark stages of the build when they should
76100
only be triggered on the full build. [#249](https://github.com/commercetools/commercetools-sync-java/issues/249)
77-
-->
78101

79102

80103
### v1.0.0-M10 - Feb 13, 2018

docs/usage/CATEGORY_SYNC.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,5 +143,4 @@ More examples of those utils for different fields can be found [here](/src/integ
143143
## Caveats
144144

145145
1. Categories are either created or updated. Currently the tool does not support category deletion.
146-
2. The library doesn't sync category assets yet [#3](https://github.com/commercetools/commercetools-sync-java/issues/3), but it will not delete them.
147-
3. The library will sync all field types of custom fields, except `ReferenceType`. [#87](https://github.com/commercetools/commercetools-sync-java/issues/3).
146+
2. The library will sync all field types of custom fields, except `ReferenceType`. [#87](https://github.com/commercetools/commercetools-sync-java/issues/3).

docs/usage/PRODUCT_SYNC.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ More examples of those utils for different fields can be found [here](/src/integ
159159

160160
## Caveats
161161
1. Products are either created or updated. Currently the tool does not support product deletion.
162-
2. The library doesn't sync product variant assets yet [#3](https://github.com/commercetools/commercetools-sync-java/issues/3), but it will not delete them.
163-
3. The library will not sync attribute field types with `ReferenceType` and `SetType` field definitions, except
162+
2. The library will not sync attribute field types with `ReferenceType` and `SetType` field definitions, except
164163
for Product references. (See more: [#87](https://github.com/commercetools/commercetools-sync-java/issues/87) [#160](https://github.com/commercetools/commercetools-sync-java/issues/87))
165164

src/integration-test/java/com/commercetools/sync/integration/commons/utils/CategoryITUtils.java

Lines changed: 9 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import com.commercetools.sync.categories.CategorySync;
44
import com.commercetools.sync.categories.helpers.CategorySyncStatistics;
5-
import com.fasterxml.jackson.databind.JsonNode;
6-
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
75
import io.sphere.sdk.categories.Category;
86
import io.sphere.sdk.categories.CategoryDraft;
97
import io.sphere.sdk.categories.CategoryDraftBuilder;
@@ -16,17 +14,9 @@
1614
import io.sphere.sdk.models.Reference;
1715
import io.sphere.sdk.products.CategoryOrderHints;
1816
import io.sphere.sdk.queries.QueryExecutionUtils;
19-
import io.sphere.sdk.queries.QueryPredicate;
20-
import io.sphere.sdk.types.BooleanFieldType;
2117
import io.sphere.sdk.types.CustomFieldsDraft;
22-
import io.sphere.sdk.types.FieldDefinition;
23-
import io.sphere.sdk.types.LocalizedStringFieldType;
2418
import io.sphere.sdk.types.ResourceTypeIdsSetBuilder;
2519
import io.sphere.sdk.types.Type;
26-
import io.sphere.sdk.types.TypeDraft;
27-
import io.sphere.sdk.types.TypeDraftBuilder;
28-
import io.sphere.sdk.types.commands.TypeCreateCommand;
29-
import io.sphere.sdk.types.queries.TypeQueryBuilder;
3020

3121
import javax.annotation.Nonnull;
3222
import javax.annotation.Nullable;
@@ -38,22 +28,21 @@
3828
import java.util.Locale;
3929
import java.util.Map;
4030
import java.util.Objects;
41-
import java.util.Optional;
4231
import java.util.Set;
4332
import java.util.concurrent.CompletableFuture;
4433
import java.util.concurrent.CompletionStage;
4534
import java.util.stream.Collectors;
4635

36+
import static com.commercetools.sync.integration.commons.utils.ITUtils.createCustomFieldsJsonMap;
37+
import static com.commercetools.sync.integration.commons.utils.ITUtils.createTypeIfNotAlreadyExisting;
4738
import static com.commercetools.sync.commons.utils.ResourceIdentifierUtils.toResourceIdentifierIfNotNull;
39+
4840
import static io.sphere.sdk.utils.CompletableFutureUtils.listOfFuturesToFutureOfList;
4941
import static java.lang.String.format;
50-
import static java.util.Arrays.asList;
5142

5243
public final class CategoryITUtils {
5344
public static final String OLD_CATEGORY_CUSTOM_TYPE_KEY = "oldCategoryCustomTypeKey";
5445
public static final String OLD_CATEGORY_CUSTOM_TYPE_NAME = "old_type_name";
55-
public static final String LOCALISED_STRING_CUSTOM_FIELD_NAME = "backgroundColor";
56-
public static final String BOOLEAN_CUSTOM_FIELD_NAME = "invisibleInShop";
5746

5847
/**
5948
* Builds a list of the supplied number ({@code numberOfCategories}) of CategoryDraft objects that can be used for
@@ -145,7 +134,7 @@ public static List<Category> createChildren(final int numberOfChildren,
145134
LocalizedString.of(Locale.ENGLISH, categoryName))
146135
.key(categoryName)
147136
.parent(toResourceIdentifierIfNotNull(parent))
148-
.custom(CustomFieldsDraft.ofTypeKeyAndJson(OLD_CATEGORY_CUSTOM_TYPE_KEY, getCustomFieldsJsons()))
137+
.custom(CustomFieldsDraft.ofTypeKeyAndJson(OLD_CATEGORY_CUSTOM_TYPE_KEY, createCustomFieldsJsonMap()))
149138
.orderHint("sameOrderHint")
150139
.build();
151140
final CompletableFuture<Category> future = ctpClient
@@ -171,24 +160,7 @@ public static List<Category> createChildren(final int numberOfChildren,
171160
* @return a dummy instance of {@link CustomFieldsDraft} with some hardcoded custom fields and key.
172161
*/
173162
public static CustomFieldsDraft getCustomFieldsDraft() {
174-
return CustomFieldsDraft.ofTypeKeyAndJson(OLD_CATEGORY_CUSTOM_TYPE_KEY, getCustomFieldsJsons());
175-
}
176-
177-
/**
178-
* Builds a {@link Map} for the custom fields to their {@link JsonNode} values that looks as follows in JSON
179-
* format:
180-
*
181-
* <p>"fields": {"invisibleInShop": false, "backgroundColor": { "en": "red", "de": "rot"}}
182-
*
183-
* @return a Map of the custom fields to their JSON values with dummy data.
184-
*/
185-
public static Map<String, JsonNode> getCustomFieldsJsons() {
186-
final Map<String, JsonNode> customFieldsJsons = new HashMap<>();
187-
customFieldsJsons.put(BOOLEAN_CUSTOM_FIELD_NAME, JsonNodeFactory.instance.booleanNode(false));
188-
customFieldsJsons
189-
.put(LOCALISED_STRING_CUSTOM_FIELD_NAME, JsonNodeFactory.instance.objectNode()
190-
.put("de", "rot").put("en", "red"));
191-
return customFieldsJsons;
163+
return CustomFieldsDraft.ofTypeKeyAndJson(OLD_CATEGORY_CUSTOM_TYPE_KEY, createCustomFieldsJsonMap());
192164
}
193165

194166
/**
@@ -218,74 +190,18 @@ public static List<Category> createCategories(@Nonnull final SphereClient ctpCli
218190
/**
219191
* This method blocks to create a category custom Type on the CTP project defined by the supplied
220192
* {@code ctpClient}, with the supplied data.
221-
*
222-
* @param typeKey the type key
193+
* @param typeKey the type key
223194
* @param locale the locale to be used for specifying the type name and field definitions names.
224195
* @param name the name of the custom type.
225196
* @param ctpClient defines the CTP project to create the type on.
226197
*/
227-
public static void createCategoriesCustomType(@Nonnull final String typeKey,
198+
public static Type createCategoriesCustomType(@Nonnull final String typeKey,
228199
@Nonnull final Locale locale,
229200
@Nonnull final String name,
230201
@Nonnull final SphereClient ctpClient) {
231-
if (!typeExists(typeKey, ctpClient)) {
232-
final TypeDraft typeDraft = TypeDraftBuilder
233-
.of(typeKey, LocalizedString.of(locale, name), ResourceTypeIdsSetBuilder.of().addCategories())
234-
.fieldDefinitions(buildCategoryCustomTypeFieldDefinitions(locale))
235-
.build();
236-
ctpClient.execute(TypeCreateCommand.of(typeDraft)).toCompletableFuture().join();
237-
}
238-
}
239-
240-
private static boolean typeExists(@Nonnull final String typeKey, @Nonnull final SphereClient ctpClient) {
241-
final Optional<Type> typeOptional = ctpClient
242-
.execute(TypeQueryBuilder.of().predicates(QueryPredicate.of(format("key=\"%s\"", typeKey))).build())
243-
.toCompletableFuture()
244-
.join().head();
245-
return typeOptional.isPresent();
246-
}
247-
248-
/**
249-
* Builds a list of two field definitions; one for a {@link LocalizedStringFieldType} and one for a
250-
* {@link BooleanFieldType}. The JSON of the created field definition list looks as follows:
251-
*
252-
* <p>"fieldDefinitions": [
253-
* {
254-
* "name": "backgroundColor",
255-
* "label": {
256-
* "en": "backgroundColor"
257-
* },
258-
* "required": false,
259-
* "type": {
260-
* "name": "LocalizedString"
261-
* },
262-
* "inputHint": "SingleLine"
263-
* },
264-
* {
265-
* "name": "invisibleInShop",
266-
* "label": {
267-
* "en": "invisibleInShop"
268-
* },
269-
* "required": false,
270-
* "type": {
271-
* "name": "Boolean"
272-
* },
273-
* "inputHint": "SingleLine"
274-
* }
275-
* ]
276-
*
277-
* @param locale defines the locale for which the field definition names are going to be bound to.
278-
* @return the list of field definitions.
279-
*/
280-
private static List<FieldDefinition> buildCategoryCustomTypeFieldDefinitions(@Nonnull final Locale locale) {
281-
return asList(
282-
FieldDefinition
283-
.of(LocalizedStringFieldType.of(), LOCALISED_STRING_CUSTOM_FIELD_NAME,
284-
LocalizedString.of(locale, LOCALISED_STRING_CUSTOM_FIELD_NAME), false),
285-
FieldDefinition
286-
.of(BooleanFieldType.of(), BOOLEAN_CUSTOM_FIELD_NAME,
287-
LocalizedString.of(locale, BOOLEAN_CUSTOM_FIELD_NAME), false));
288202

203+
return createTypeIfNotAlreadyExisting(typeKey, locale, name, ResourceTypeIdsSetBuilder.of().addCategories(),
204+
ctpClient);
289205
}
290206

291207

0 commit comments

Comments
 (0)