Skip to content

#300: Add support for sync of custom types#304

Closed
ahmetoz wants to merge 43 commits intomasterfrom
300-feature-type-sync
Closed

#300: Add support for sync of custom types#304
ahmetoz wants to merge 43 commits intomasterfrom
300-feature-type-sync

Conversation

@ahmetoz
Copy link
Copy Markdown
Contributor

@ahmetoz ahmetoz commented Sep 13, 2018

Summary

Adds implementations for the type sync.

Description

Relevant Issues

#300

Todo

  • Tests

    • Unit
    • Integration
    • Benchmark
  • Documentation

  • Add Release Notes entry.

Hints for Review

@ahmetoz ahmetoz requested a review from a team September 19, 2018 15:18
@codecov-io
Copy link
Copy Markdown

codecov-io commented Sep 20, 2018

Codecov Report

Merging #304 into master will increase coverage by 0.17%.
The diff coverage is 98.89%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #304      +/-   ##
============================================
+ Coverage     96.91%   97.09%   +0.17%     
- Complexity     1097     1203     +106     
============================================
  Files           104      116      +12     
  Lines          2693     2963     +270     
  Branches        129      137       +8     
============================================
+ Hits           2610     2877     +267     
- Misses           71       72       +1     
- Partials         12       14       +2
Impacted Files Coverage Δ Complexity Δ
.../types/utils/FieldDefinitionUpdateActionUtils.java 100% <100%> (ø) 9 <9> (?)
...mercetools/sync/services/impl/TypeServiceImpl.java 100% <100%> (ø) 16 <9> (+9) ⬆️
.../commercetools/sync/types/utils/TypeSyncUtils.java 100% <100%> (ø) 1 <1> (?)
...mercetools/sync/types/helpers/FieldTypeAssert.java 100% <100%> (ø) 7 <7> (?)
...types/utils/FieldDefinitionsUpdateActionUtils.java 100% <100%> (ø) 20 <20> (?)
...tools/sync/types/utils/EnumUpdateActionsUtils.java 100% <100%> (ø) 11 <11> (?)
.../com/commercetools/sync/types/TypeSyncOptions.java 100% <100%> (ø) 1 <1> (?)
...etools/sync/types/utils/TypeUpdateActionUtils.java 100% <100%> (ø) 5 <5> (?)
...mmercetools/sync/types/TypeSyncOptionsBuilder.java 100% <100%> (ø) 4 <4> (?)
...cetools/sync/types/helpers/TypeSyncStatistics.java 100% <100%> (ø) 2 <2> (?)
... and 15 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 eb67c4d...880ae86. Read the comment docs.

@ahmetoz ahmetoz changed the title #300: Add support for sync of custom types WIP #300: Add support for sync of custom types Sep 24, 2018
@ahmetoz ahmetoz changed the title WIP #300: Add support for sync of custom types #300: Add support for sync of custom types Sep 24, 2018
@ahmetoz ahmetoz closed this Sep 24, 2018
@ahmetoz ahmetoz deleted the 300-feature-type-sync branch September 24, 2018 12:23
@ahmetoz ahmetoz restored the 300-feature-type-sync branch September 24, 2018 12:24
@ahmetoz ahmetoz reopened this Sep 24, 2018
Copy link
Copy Markdown
Contributor

@lojzatran lojzatran left a comment

Choose a reason for hiding this comment

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

Nice work with this PR! I found few things that needs to be addressed or answered.

Pls also update the product type sync if you address the changes, because it seems like you got a lot of inspirations from there.

Comment thread src/main/java/com/commercetools/sync/services/TypeService.java Outdated
Comment thread src/main/java/com/commercetools/sync/services/TypeService.java Outdated
Comment thread src/main/java/com/commercetools/sync/services/TypeService.java Outdated
Comment thread src/main/java/com/commercetools/sync/services/TypeService.java Outdated
Comment thread src/main/java/com/commercetools/sync/services/TypeService.java Outdated
// remove enum value actions not exists for type resources
assertThat(updateActions).containsExactly(
ChangeLocalizedEnumValueOrder.of(FIELD_NAME_1, asList(
ENUM_VALUE_C.getKey(),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What about A? Don't you have to have all enums in this action?

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.

A should be removed but it's not supported by the API.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would keep a test that its failing for it but mark it with @ignore annotation and a TODO comment to fix it once the API provides it.

Comment thread docs/usage/TYPE_SYNC.md Outdated
Comment thread docs/usage/TYPE_SYNC.md Outdated
Comment thread docs/usage/TYPE_SYNC.md
Comment thread docs/usage/TYPE_SYNC.md Outdated
- Retries on 5xx errors with a retry strategy. This can be achieved by decorating the `sphereClient` with the
[RetrySphereClientDecorator](http://commercetools.github.io/commercetools-jvm-sdk/apidocs/io/sphere/sdk/client/RetrySphereClientDecorator.html)

You can use the same client instantiating used in the integration tests for this library found
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

...You can use the same client instance in the integration tests

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.

Copy link
Copy Markdown
Contributor

@heshamMassoud heshamMassoud Oct 4, 2018

Choose a reason for hiding this comment

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

@ahalberkamp @ahmetoz no actually it's not meant to say you can use the "same client instance". It should be along the lines: "You can instantiate the client the same way it is instantiated in the integration tests for this library found.."

Copy link
Copy Markdown
Contributor

@heshamMassoud heshamMassoud Oct 4, 2018

Choose a reason for hiding this comment

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

@ahmetoz As mentioned here. It would be great if you adapt any comments in the similar docs :)

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.

@Nonnull final List<TypeDraft> typeDrafts) {

final List<List<TypeDraft>> batches = batchElements(typeDrafts, syncOptions.getBatchSize());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Remove empty line

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.

@ahmetoz
Copy link
Copy Markdown
Contributor Author

ahmetoz commented Oct 4, 2018

What is empty updated/created statistics?

I could not find a fancy name for it 😅

@lojzatran
Copy link
Copy Markdown
Contributor

I could not find a fancy name for it 😅

You should find a fancy name :) It's open-source repo and everybody can see our code.

@heshamMassoud
Copy link
Copy Markdown
Contributor

heshamMassoud commented Oct 4, 2018

Usually I add a release notes entry for what has changed/added/enhances/fixed (that the user of the library needs to know) in the PR in the commented out section that it will be released in. The release notes file is: docs/RELEASE_NOTES.md.

This also includes any public methods/utils that users from outside the library can use or cannot use anymore. Or are already using and some behaviour has changed for example.

Please add entries related to your PR there too :)

Copy link
Copy Markdown
Contributor

@heshamMassoud heshamMassoud left a comment

Choose a reason for hiding this comment

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

Good work @ahmetoz! I added a first review of this PR.

Comment thread docs/RELEASE_NOTES.md Outdated
[Javadoc](https://commercetools.github.io/commercetools-sync-java/v/v1.0.0-M14/) |
[Jar](https://bintray.com/commercetools/maven/commercetools-sync-java/v1.0.0-M14)

**New Features** (1)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please add also entries for all the public utils that were added.

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/usage/TYPE_SYNC.md

1. Types are either created or updated. Currently the tool does not support type deletion.
2. Updating the label of enum values and localized enum values of field definition is not supported yet.
3. Removing the enum values from the field definition is not supported yet.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nice that you added them as caveats here 😊Would be great if you can also mention/link the CTP support tickets related to them (of course only if they are public) so we can cross relate them in the future.

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.

Tickets for the issues are not public 👎

Comment thread docs/usage/TYPE_SYNC.md Outdated

__Note__ The statistics object contains the processing time of the last batch only. This is due to two reasons:
1. The sync processing time should not take into account the time between supplying batches to the sync.
2. It is not not known by the sync which batch is going to be the last one supplied.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It is not not -> It is not

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.


/**
* Creates new instance of {@link TypeSyncOptions} enriched with all fields provided to {@code this}
* builder.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

builder doesn't have to be on a separate line 😉

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.

import javax.annotation.Nonnull;

public final class TypeSyncOptionsBuilder extends BaseSyncOptionsBuilder<TypeSyncOptionsBuilder,
TypeSyncOptions, Type, TypeDraft> {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this line is extra indented..

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.

* @return A list with the update actions or an empty list if the field definition fields are identical.
*/
@Nonnull
public static List<UpdateAction<Type>> buildActions(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@ahmetoz you are handling type changes here by the work around of (remove-then-add)

final Map<String, Type> oldTypeMap = getKeysTypeMap(oldTypes);

return CompletableFuture.allOf(newTypes
.stream()
Copy link
Copy Markdown
Contributor

@heshamMassoud heshamMassoud Oct 4, 2018

Choose a reason for hiding this comment

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

Its always more readable if you indent the chain dots of the same level with the same indentation level.

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.

*/
@Nonnull
CompletionStage<Optional<String>> fetchCachedTypeId(@Nonnull final String key);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please cover the newly added services with integration tests.

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.

// remove enum value actions not exists for type resources
assertThat(updateActions).containsExactly(
ChangeLocalizedEnumValueOrder.of(FIELD_NAME_1, asList(
ENUM_VALUE_C.getKey(),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would keep a test that its failing for it but mark it with @ignore annotation and a TODO comment to fix it once the API provides it.

);

assertThat(updateActions).containsExactly(
RemoveFieldDefinition.of(FIELD_A),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In this test you are testing the fact the correct update actions have been built. Only in this test, the order doesn't matter. So you should actually assert with containsExactlyInAnyOrder not with containsExactly.

However, order definitely matters which update actions are generated before which. But this should have it's own unit test focusing on testing the order of the generated actions with a strict containsExactly assert. This way you don't test two things together.

@heshamMassoud
Copy link
Copy Markdown
Contributor

In general I see a lot of code duplication between the Type sync and the Product Type sync especially with the enum implementations. I think we should move the common parts to the commons package and resuse:

  1. Less code duplication
  2. Less test duplication
  3. Less error prone.

@ahmetoz ahmetoz self-assigned this Oct 18, 2018
@ahmetoz ahmetoz mentioned this pull request Nov 14, 2018
5 tasks
@ahmetoz ahmetoz closed this Nov 14, 2018
@heshamMassoud heshamMassoud deleted the 300-feature-type-sync branch December 7, 2018 09: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.

5 participants