Skip to content

169: beforeUpdateCallback#184

Merged
heshamMassoud merged 47 commits intomasterfrom
169-update-actions-filter
Nov 16, 2017
Merged

169: beforeUpdateCallback#184
heshamMassoud merged 47 commits intomasterfrom
169-update-actions-filter

Conversation

@heshamMassoud
Copy link
Copy Markdown
Contributor

@heshamMassoud heshamMassoud commented Nov 14, 2017

Summary

  1. Rename the option updateActionsFilter to beforeUpdateCallback and make it more generic in the base sync option builders for all sync options to use: 2af6c3e, 6118485, 943b76b, 252a43a

  2. beforeUpdateCallback is now a TriFunction which accepts three arguments update actions list, old resource and new resource draft: 1428876, 274af7d

  3. Remove the set prefix in all option builders (e.g. setSyncFilter, setBatchSize, etc.. to syncFilter, batchSize, etc..) : fba0ba5, 3beab28, 904bd1e, 93f7dba

  4. Removal of option removeOtherLocales since it can now be achieved through new beforeUpdateCallback: c117e1f

  5. Provide IT for beforeUpdateCallback to sync only a sinlgle localization (french) of products: here

Relevant Issues

#169 #183

@codecov-io
Copy link
Copy Markdown

codecov-io commented Nov 14, 2017

Codecov Report

Merging #184 into master will decrease coverage by 2.47%.
The diff coverage is 23.94%.

Impacted file tree graph

@@             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
Impacted Files Coverage Δ Complexity Δ
...ls/sync/commons/helpers/BaseReferenceResolver.java 100% <ø> (ø) 11 <0> (ø) ⬇️
...cetools/sync/inventories/InventorySyncOptions.java 100% <ø> (ø) 2 <0> (ø) ⬇️
...ercetools/sync/categories/CategorySyncOptions.java 100% <ø> (ø) 1 <0> (-1) ⬇️
...mplates/beforeupdatecallback/SyncSingleLocale.java 0% <0%> (ø) 0 <0> (?)
...ercetools/sync/commons/BaseSyncOptionsBuilder.java 100% <100%> (ø) 10 <4> (ø) ⬇️
...tools/sync/categories/utils/CategorySyncUtils.java 96.15% <100%> (-0.15%) 4 <0> (-2)
...ols/sync/inventories/utils/InventorySyncUtils.java 91.66% <100%> (ø) 1 <0> (ø) ⬇️
...ommercetools/sync/products/ProductSyncOptions.java 87.5% <100%> (-2.5%) 3 <1> (-1)
...om/commercetools/sync/commons/BaseSyncOptions.java 100% <100%> (ø) 17 <3> (+2) ⬆️
...rcetools/sync/products/utils/ProductSyncUtils.java 97.72% <100%> (-0.06%) 15 <0> (-2)
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4693ab8...24b61bf. Read the comment docs.

@heshamMassoud heshamMassoud changed the title WIP: 169 beforeUpdateCallback 169: beforeUpdateCallback Nov 15, 2017
Comment thread docs/RELEASE_NOTES.md Outdated
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)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe better: Compatibility notes -> Migration guide

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread docs/RELEASE_NOTES.md Outdated
[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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-> Introduced beforeUpdateCallback which is applied after generation of update actions and before actual resource update.

Copy link
Copy Markdown
Contributor Author

@heshamMassoud heshamMassoud Nov 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like wording and the way things are described in our JVM SDK. We could apply same wording, wdyt?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to past tense: c1c6629

Comment thread docs/RELEASE_NOTES.md Outdated
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,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is now -> has been renamed to.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread docs/RELEASE_NOTES.md Outdated

**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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

namley -> namely

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread docs/RELEASE_NOTES.md Outdated
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)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change name -> Renamed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

private List<UpdateAction<Product>> updateActionsCallback(@Nonnull final List<UpdateAction<Product>> builtActions) {
private List<UpdateAction<Product>> beforeUpdateCallback(@Nonnull final List<UpdateAction<Product>> builtActions,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not updateActions instead of builtActions?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

},
"catalogs": [],
"masterData": {
"current": {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably need stage only?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.contains(LocalizedString.of(Locale.ENGLISH, "english description.", Locale.FRENCH, "french description."));

assertThat(updateActionsFromSync.stream()
.filter(updateAction -> updateAction instanceof ChangeSlug)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

related to: #184 (comment)

if (updateAction instanceof SetMetaKeywords) {
return filterLocalizedField(newDraft, oldProduct, locale, ProductDraft::getMetaKeywords,
ProductData::getMetaKeywords, SetMetaKeywords::of);
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also here it might be interesting to filter also localized attribute changes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If oldLocaleValue is null than it should ensure that newLocalizedField has French locale only, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if oldLocalValue is null, then it will set the new French locale (if it exists). But it shouldn't touch other locales.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The thing is that for some properties (like product description) "oldLocalizedField" might be not set yet so you will run into NPE.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, now I know what you mean. You are right: I fixed the logic here: 2f3bb99

@heshamMassoud heshamMassoud merged commit 7fbad35 into master Nov 16, 2017
@heshamMassoud heshamMassoud deleted the 169-update-actions-filter branch November 16, 2017 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants