169: beforeUpdateCallback#184
Conversation
… and warningCallback.
…in old resource and new resource draft.
Codecov Report
@@ Coverage Diff @@
## master #184 +/- ##
============================================
- Coverage 95.22% 92.74% -2.48%
+ Complexity 795 789 -6
============================================
Files 65 66 +1
Lines 2052 2096 +44
Branches 98 112 +14
============================================
- Hits 1954 1944 -10
- Misses 79 133 +54
Partials 19 19
Continue to review full report at Codecov.
|
| which adds more information about the generated list of update actions, namley, the old resource being updated and the new | ||
| resource draft. [#169](https://github.com/commercetools/commercetools-sync-java/issues/169) | ||
|
|
||
| **Compatibility notes** (8) |
There was a problem hiding this comment.
Maybe better: Compatibility notes -> Migration guide
| [Jar](https://bintray.com/commercetools/maven/commercetools-sync-java/v1.0.0-M5) | ||
|
|
||
| **New Features** (1) | ||
| - **Inventory Sync** - Support of `beforeUpdateCallback` which is callback function that is applied on the generated list |
There was a problem hiding this comment.
-> Introduced beforeUpdateCallback which is applied after generation of update actions and before actual resource update.
There was a problem hiding this comment.
I intentionally use present tense to convey the meaning that this release "ships", "introduces", "supports", etc. this feature to the library. I've seen it in several release notes of different applications (also mentioned here: https://en.wikipedia.org/wiki/Release_notes)
Change of wording according to your request is here: 5346956
I have found that I was not consistent throughout this release notes though. What do you think should be the tense? Is there a specific reason you use paste tense? (accordingly I will make the release notes use consistent tense)
There was a problem hiding this comment.
I like wording and the way things are described in our JVM SDK. We could apply same wording, wdyt?
There was a problem hiding this comment.
I personally don't have a strong opinion about, so we can be consistent with JVM SDK as another lib of CT and also use past tense
| of update actions from syncing an old InventoryEntry with a new InventoryEntryDraft. [#169](https://github.com/commercetools/commercetools-sync-java/issues/169) | ||
|
|
||
| **Enhancements** (1) | ||
| - **Commons** - `setUpdateActionsCallback` is now `beforeUpdateCallback` and takes a TriFunction instead of Function, |
There was a problem hiding this comment.
is now -> has been renamed to.
There was a problem hiding this comment.
|
|
||
| **Enhancements** (1) | ||
| - **Commons** - `setUpdateActionsCallback` is now `beforeUpdateCallback` and takes a TriFunction instead of Function, | ||
| which adds more information about the generated list of update actions, namley, the old resource being updated and the new |
| resource draft. [#169](https://github.com/commercetools/commercetools-sync-java/issues/169) | ||
|
|
||
| **Compatibility notes** (8) | ||
| - **Commons** - Change name of `setUpdateActionsCallback` to `beforeUpdateCallback`. [#169](https://github.com/commercetools/commercetools-sync-java/issues/169) |
| } | ||
|
|
||
| private List<UpdateAction<Product>> updateActionsCallback(@Nonnull final List<UpdateAction<Product>> builtActions) { | ||
| private List<UpdateAction<Product>> beforeUpdateCallback(@Nonnull final List<UpdateAction<Product>> builtActions, |
There was a problem hiding this comment.
Why not updateActions instead of builtActions?
| }, | ||
| "catalogs": [], | ||
| "masterData": { | ||
| "current": { |
| .contains(LocalizedString.of(Locale.ENGLISH, "english description.", Locale.FRENCH, "french description.")); | ||
|
|
||
| assertThat(updateActionsFromSync.stream() | ||
| .filter(updateAction -> updateAction instanceof ChangeSlug) |
There was a problem hiding this comment.
Maybe it makes sense to check for attribute update action with defined locales here too: https://github.com/commercetools/commercetools-sync-java/pull/184/files#diff-833857ed4fc9f1f796dae935c89b5d12R189
| if (updateAction instanceof SetMetaKeywords) { | ||
| return filterLocalizedField(newDraft, oldProduct, locale, ProductDraft::getMetaKeywords, | ||
| ProductData::getMetaKeywords, SetMetaKeywords::of); | ||
| } |
There was a problem hiding this comment.
Also here it might be interesting to filter also localized attribute changes.
There was a problem hiding this comment.
But for this, we would need the product type to know the attribute type if its localized or not. Could be done in a "hacky" to check if the JSON object has the keys "en", "de", etc.. as keys for example. But I didn't want to include that hacky why in the test and left up to the user of the callback how they want to implement it. WDYT?
| final String oldLocaleValue = oldLocalizedField.get(locale); | ||
| if (!Objects.equals(newLocaleValue, oldLocaleValue)) { | ||
| LocalizedString withLocaleChange = oldLocalizedField; | ||
| if (oldLocaleValue != null) { |
There was a problem hiding this comment.
If oldLocaleValue is null than it should ensure that newLocalizedField has French locale only, right?
There was a problem hiding this comment.
if oldLocalValue is null, then it will set the new French locale (if it exists). But it shouldn't touch other locales.
There was a problem hiding this comment.
The thing is that for some properties (like product description) "oldLocalizedField" might be not set yet so you will run into NPE.
There was a problem hiding this comment.
Ah, now I know what you mean. You are right: I fixed the logic here: 2f3bb99
# Conflicts: # docs/RELEASE_NOTES.md
Summary
Rename the option
updateActionsFiltertobeforeUpdateCallbackand make it more generic in the base sync option builders for all sync options to use: 2af6c3e, 6118485, 943b76b, 252a43abeforeUpdateCallbackis now a TriFunction which accepts three arguments update actions list, old resource and new resource draft: 1428876, 274af7dRemove the
setprefix in all option builders (e.g.setSyncFilter,setBatchSize, etc.. tosyncFilter,batchSize, etc..) : fba0ba5, 3beab28, 904bd1e, 93f7dbaRemoval of option
removeOtherLocalessince it can now be achieved through newbeforeUpdateCallback: c117e1fProvide IT for
beforeUpdateCallbackto sync only a sinlgle localization (french) of products: hereRelevant Issues
#169 #183