Search in sources :

Example 1 with ShoppingListSync

use of com.commercetools.sync.shoppinglists.ShoppingListSync in project commercetools-project-sync by commercetools.

the class ShoppingListSyncer method of.

public static ShoppingListSyncer of(@Nonnull final SphereClient sourceClient, @Nonnull final SphereClient targetClient, @Nonnull final Clock clock) {
    final QuadConsumer<SyncException, Optional<ShoppingListDraft>, Optional<ShoppingList>, List<UpdateAction<ShoppingList>>> logErrorCallback = (exception, newResourceDraft, oldResource, updateActions) -> logErrorCallback(LOGGER, "shoppingList", exception, oldResource.map(ShoppingList::getKey).orElse(IDENTIFIER_NOT_PRESENT), updateActions);
    final TriConsumer<SyncException, Optional<ShoppingListDraft>, Optional<ShoppingList>> logWarningCallback = (exception, newResourceDraft, oldResource) -> logWarningCallback(LOGGER, "shoppingList", exception, oldResource.map(ShoppingList::getKey).orElse(IDENTIFIER_NOT_PRESENT));
    final ShoppingListSyncOptions shoppingListSyncOptions = ShoppingListSyncOptionsBuilder.of(targetClient).errorCallback(logErrorCallback).warningCallback(logWarningCallback).build();
    final ShoppingListSync shoppingListSync = new ShoppingListSync(shoppingListSyncOptions);
    final CustomObjectService customObjectService = new CustomObjectServiceImpl(targetClient);
    return new ShoppingListSyncer(shoppingListSync, sourceClient, targetClient, customObjectService, clock);
}
Also used : SyncException(com.commercetools.sync.commons.exceptions.SyncException) ShoppingListSyncOptions(com.commercetools.sync.shoppinglists.ShoppingListSyncOptions) LoggerFactory(org.slf4j.LoggerFactory) UpdateAction(io.sphere.sdk.commands.UpdateAction) QuadConsumer(com.commercetools.sync.commons.utils.QuadConsumer) ShoppingList(io.sphere.sdk.shoppinglists.ShoppingList) ShoppingListQuery(io.sphere.sdk.shoppinglists.queries.ShoppingListQuery) ShoppingListSyncOptionsBuilder(com.commercetools.sync.shoppinglists.ShoppingListSyncOptionsBuilder) SyncUtils.logWarningCallback(com.commercetools.project.sync.util.SyncUtils.logWarningCallback) SphereClient(io.sphere.sdk.client.SphereClient) TriConsumer(com.commercetools.sync.commons.utils.TriConsumer) Nonnull(javax.annotation.Nonnull) SyncUtils.logErrorCallback(com.commercetools.project.sync.util.SyncUtils.logErrorCallback) Logger(org.slf4j.Logger) ShoppingListSync(com.commercetools.sync.shoppinglists.ShoppingListSync) ShoppingListSyncStatistics(com.commercetools.sync.shoppinglists.helpers.ShoppingListSyncStatistics) IDENTIFIER_NOT_PRESENT(com.commercetools.project.sync.util.SyncUtils.IDENTIFIER_NOT_PRESENT) CustomObjectService(com.commercetools.project.sync.service.CustomObjectService) ShoppingListTransformUtils.toShoppingListDrafts(com.commercetools.sync.shoppinglists.utils.ShoppingListTransformUtils.toShoppingListDrafts) ShoppingListReferenceResolutionUtils.buildShoppingListQuery(com.commercetools.sync.shoppinglists.utils.ShoppingListReferenceResolutionUtils.buildShoppingListQuery) ShoppingListDraft(io.sphere.sdk.shoppinglists.ShoppingListDraft) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) Syncer(com.commercetools.project.sync.Syncer) Clock(java.time.Clock) Optional(java.util.Optional) CustomObjectServiceImpl(com.commercetools.project.sync.service.impl.CustomObjectServiceImpl) CustomObjectService(com.commercetools.project.sync.service.CustomObjectService) Optional(java.util.Optional) ShoppingList(io.sphere.sdk.shoppinglists.ShoppingList) ShoppingListSync(com.commercetools.sync.shoppinglists.ShoppingListSync) CustomObjectServiceImpl(com.commercetools.project.sync.service.impl.CustomObjectServiceImpl) ShoppingListSyncOptions(com.commercetools.sync.shoppinglists.ShoppingListSyncOptions) ShoppingList(io.sphere.sdk.shoppinglists.ShoppingList) List(java.util.List) SyncException(com.commercetools.sync.commons.exceptions.SyncException)

Example 2 with ShoppingListSync

use of com.commercetools.sync.shoppinglists.ShoppingListSync in project commercetools-sync-java by commercetools.

the class ShoppingListSyncIT method setUpShoppingListSync.

private void setUpShoppingListSync() {
    errorMessages = new ArrayList<>();
    warningMessages = new ArrayList<>();
    exceptions = new ArrayList<>();
    updateActionList = new ArrayList<>();
    final ShoppingListSyncOptions shoppingListSyncOptions = ShoppingListSyncOptionsBuilder.of(CTP_TARGET_CLIENT).errorCallback((exception, oldResource, newResource, actions) -> {
        errorMessages.add(exception.getMessage());
        exceptions.add(exception);
    }).warningCallback((exception, oldResource, newResource) -> warningMessages.add(exception.getMessage())).beforeUpdateCallback((updateActions, customerDraft, customer) -> {
        updateActionList.addAll(Objects.requireNonNull(updateActions));
        return updateActions;
    }).build();
    shoppingListSync = new ShoppingListSync(shoppingListSyncOptions);
}
Also used : SetLineItemCustomField(io.sphere.sdk.shoppinglists.commands.updateactions.SetLineItemCustomField) AddTextLineItem(io.sphere.sdk.shoppinglists.commands.updateactions.AddTextLineItem) BeforeEach(org.junit.jupiter.api.BeforeEach) LineItem(io.sphere.sdk.shoppinglists.LineItem) TextLineItemDraftBuilder(io.sphere.sdk.shoppinglists.TextLineItemDraftBuilder) Reference(io.sphere.sdk.models.Reference) ChangeTextLineItemName(io.sphere.sdk.shoppinglists.commands.updateactions.ChangeTextLineItemName) SetCustomField(io.sphere.sdk.shoppinglists.commands.updateactions.SetCustomField) CTP_SOURCE_CLIENT(com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_SOURCE_CLIENT) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ShoppingListSyncOptions(com.commercetools.sync.shoppinglists.ShoppingListSyncOptions) ZonedDateTime(java.time.ZonedDateTime) ShoppingListITUtils.buildIngredientCustomType(com.commercetools.sync.integration.commons.utils.ShoppingListITUtils.buildIngredientCustomType) SetSlug(io.sphere.sdk.shoppinglists.commands.updateactions.SetSlug) UpdateAction(io.sphere.sdk.commands.UpdateAction) ShoppingListTransformUtils(com.commercetools.sync.shoppinglists.utils.ShoppingListTransformUtils) Collections.singletonList(java.util.Collections.singletonList) AfterAll(org.junit.jupiter.api.AfterAll) ReferenceIdToKeyCache(com.commercetools.sync.commons.utils.ReferenceIdToKeyCache) SetTextLineItemCustomField(io.sphere.sdk.shoppinglists.commands.updateactions.SetTextLineItemCustomField) Map(java.util.Map) RemoveLineItem(io.sphere.sdk.shoppinglists.commands.updateactions.RemoveLineItem) JsonNode(com.fasterxml.jackson.databind.JsonNode) TextLineItemDraftDsl(io.sphere.sdk.shoppinglists.TextLineItemDraftDsl) Collectors.toSet(java.util.stream.Collectors.toSet) LineItemDraft(io.sphere.sdk.shoppinglists.LineItemDraft) ShoppingListDraftBuilder(io.sphere.sdk.shoppinglists.ShoppingListDraftBuilder) TextLineItem(io.sphere.sdk.shoppinglists.TextLineItem) ShoppingListSync(com.commercetools.sync.shoppinglists.ShoppingListSync) ShoppingListSyncStatistics(com.commercetools.sync.shoppinglists.helpers.ShoppingListSyncStatistics) LineItemDraftBuilder(io.sphere.sdk.shoppinglists.LineItemDraftBuilder) ChangeLineItemQuantity(io.sphere.sdk.shoppinglists.commands.updateactions.ChangeLineItemQuantity) SetDescription(io.sphere.sdk.shoppinglists.commands.updateactions.SetDescription) Collection(java.util.Collection) ShoppingListITUtils.deleteShoppingListTestData(com.commercetools.sync.integration.commons.utils.ShoppingListITUtils.deleteShoppingListTestData) ChangeName(io.sphere.sdk.shoppinglists.commands.updateactions.ChangeName) Set(java.util.Set) ShoppingListITUtils.createSampleShoppingListCarrotCake(com.commercetools.sync.integration.commons.utils.ShoppingListITUtils.createSampleShoppingListCarrotCake) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) LocalizedString(io.sphere.sdk.models.LocalizedString) List(java.util.List) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory) CTP_TARGET_CLIENT(com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT) CustomFields(io.sphere.sdk.types.CustomFields) SetAnonymousId(io.sphere.sdk.shoppinglists.commands.updateactions.SetAnonymousId) TextLineItemDraft(io.sphere.sdk.shoppinglists.TextLineItemDraft) AssertionsForStatistics.assertThat(com.commercetools.sync.commons.asserts.statistics.AssertionsForStatistics.assertThat) HashMap(java.util.HashMap) ShoppingList(io.sphere.sdk.shoppinglists.ShoppingList) ChangeTextLineItemQuantity(io.sphere.sdk.shoppinglists.commands.updateactions.ChangeTextLineItemQuantity) ShoppingListSyncOptionsBuilder(com.commercetools.sync.shoppinglists.ShoppingListSyncOptionsBuilder) ArrayList(java.util.ArrayList) AddLineItem(io.sphere.sdk.shoppinglists.commands.updateactions.AddLineItem) SetDeleteDaysAfterLastModification(io.sphere.sdk.shoppinglists.commands.updateactions.SetDeleteDaysAfterLastModification) SetTextLineItemDescription(io.sphere.sdk.shoppinglists.commands.updateactions.SetTextLineItemDescription) Nonnull(javax.annotation.Nonnull) CaffeineReferenceIdToKeyCacheImpl(com.commercetools.sync.commons.utils.CaffeineReferenceIdToKeyCacheImpl) ShoppingListITUtils.buildUtensilsCustomType(com.commercetools.sync.integration.commons.utils.ShoppingListITUtils.buildUtensilsCustomType) ShoppingListReferenceResolutionUtils.buildShoppingListQuery(com.commercetools.sync.shoppinglists.utils.ShoppingListReferenceResolutionUtils.buildShoppingListQuery) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) Collectors.toList(java.util.stream.Collectors.toList) ShoppingListDraft(io.sphere.sdk.shoppinglists.ShoppingListDraft) CustomFieldsDraft(io.sphere.sdk.types.CustomFieldsDraft) ShoppingListSync(com.commercetools.sync.shoppinglists.ShoppingListSync) ShoppingListSyncOptions(com.commercetools.sync.shoppinglists.ShoppingListSyncOptions)

Example 3 with ShoppingListSync

use of com.commercetools.sync.shoppinglists.ShoppingListSync in project commercetools-sync-java by commercetools.

the class ShoppingListSyncIT method setUpShoppingListSync.

private void setUpShoppingListSync() {
    errorMessages = new ArrayList<>();
    warningMessages = new ArrayList<>();
    exceptions = new ArrayList<>();
    updateActionList = new ArrayList<>();
    final ShoppingListSyncOptions shoppingListSyncOptions = ShoppingListSyncOptionsBuilder.of(CTP_TARGET_CLIENT).errorCallback((exception, oldResource, newResource, actions) -> {
        errorMessages.add(exception.getMessage());
        exceptions.add(exception);
    }).warningCallback((exception, oldResource, newResource) -> warningMessages.add(exception.getMessage())).beforeUpdateCallback((updateActions, customerDraft, customer) -> {
        updateActionList.addAll(Objects.requireNonNull(updateActions));
        return updateActions;
    }).build();
    shoppingListSync = new ShoppingListSync(shoppingListSyncOptions);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Reference(io.sphere.sdk.models.Reference) CTP_SOURCE_CLIENT(com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_SOURCE_CLIENT) SetAnonymousId(io.sphere.sdk.shoppinglists.commands.updateactions.SetAnonymousId) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ShoppingListSyncOptions(com.commercetools.sync.shoppinglists.ShoppingListSyncOptions) AssertionsForStatistics.assertThat(com.commercetools.sync.commons.asserts.statistics.AssertionsForStatistics.assertThat) UpdateAction(io.sphere.sdk.commands.UpdateAction) ShoppingList(io.sphere.sdk.shoppinglists.ShoppingList) ShoppingListSyncOptionsBuilder(com.commercetools.sync.shoppinglists.ShoppingListSyncOptionsBuilder) ShoppingListTransformUtils(com.commercetools.sync.shoppinglists.utils.ShoppingListTransformUtils) ArrayList(java.util.ArrayList) AfterAll(org.junit.jupiter.api.AfterAll) ShoppingListITUtils.createShoppingList(com.commercetools.sync.integration.commons.utils.ShoppingListITUtils.createShoppingList) ReferenceIdToKeyCache(com.commercetools.sync.commons.utils.ReferenceIdToKeyCache) ShoppingListDraftBuilder(io.sphere.sdk.shoppinglists.ShoppingListDraftBuilder) CustomerITUtils.createSampleCustomerJaneDoe(com.commercetools.sync.integration.commons.utils.CustomerITUtils.createSampleCustomerJaneDoe) CaffeineReferenceIdToKeyCacheImpl(com.commercetools.sync.commons.utils.CaffeineReferenceIdToKeyCacheImpl) ShoppingListSync(com.commercetools.sync.shoppinglists.ShoppingListSync) ShoppingListSyncStatistics(com.commercetools.sync.shoppinglists.helpers.ShoppingListSyncStatistics) ShoppingListITUtils.deleteShoppingListTestData(com.commercetools.sync.integration.commons.utils.ShoppingListITUtils.deleteShoppingListTestData) ChangeName(io.sphere.sdk.shoppinglists.commands.updateactions.ChangeName) ShoppingListITUtils.createSampleShoppingListCarrotCake(com.commercetools.sync.integration.commons.utils.ShoppingListITUtils.createSampleShoppingListCarrotCake) Customer(io.sphere.sdk.customers.Customer) Collectors(java.util.stream.Collectors) ShoppingListReferenceResolutionUtils.buildShoppingListQuery(com.commercetools.sync.shoppinglists.utils.ShoppingListReferenceResolutionUtils.buildShoppingListQuery) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) LocalizedString(io.sphere.sdk.models.LocalizedString) ShoppingListDraft(io.sphere.sdk.shoppinglists.ShoppingListDraft) List(java.util.List) SetCustomer(io.sphere.sdk.shoppinglists.commands.updateactions.SetCustomer) AssertionsForStatistics(com.commercetools.sync.commons.asserts.statistics.AssertionsForStatistics) CTP_TARGET_CLIENT(com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT) ResourceIdentifier(io.sphere.sdk.models.ResourceIdentifier) ShoppingListSync(com.commercetools.sync.shoppinglists.ShoppingListSync) ShoppingListSyncOptions(com.commercetools.sync.shoppinglists.ShoppingListSyncOptions)

Aggregations

ShoppingListSync (com.commercetools.sync.shoppinglists.ShoppingListSync)3 ShoppingListSyncOptions (com.commercetools.sync.shoppinglists.ShoppingListSyncOptions)3 ShoppingListSyncOptionsBuilder (com.commercetools.sync.shoppinglists.ShoppingListSyncOptionsBuilder)3 ShoppingListSyncStatistics (com.commercetools.sync.shoppinglists.helpers.ShoppingListSyncStatistics)3 ShoppingListReferenceResolutionUtils.buildShoppingListQuery (com.commercetools.sync.shoppinglists.utils.ShoppingListReferenceResolutionUtils.buildShoppingListQuery)3 UpdateAction (io.sphere.sdk.commands.UpdateAction)3 ShoppingList (io.sphere.sdk.shoppinglists.ShoppingList)3 ShoppingListDraft (io.sphere.sdk.shoppinglists.ShoppingListDraft)3 List (java.util.List)3 AssertionsForStatistics.assertThat (com.commercetools.sync.commons.asserts.statistics.AssertionsForStatistics.assertThat)2 CaffeineReferenceIdToKeyCacheImpl (com.commercetools.sync.commons.utils.CaffeineReferenceIdToKeyCacheImpl)2 ReferenceIdToKeyCache (com.commercetools.sync.commons.utils.ReferenceIdToKeyCache)2 ShoppingListITUtils.createSampleShoppingListCarrotCake (com.commercetools.sync.integration.commons.utils.ShoppingListITUtils.createSampleShoppingListCarrotCake)2 ShoppingListITUtils.deleteShoppingListTestData (com.commercetools.sync.integration.commons.utils.ShoppingListITUtils.deleteShoppingListTestData)2 CTP_SOURCE_CLIENT (com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_SOURCE_CLIENT)2 CTP_TARGET_CLIENT (com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT)2 ShoppingListTransformUtils (com.commercetools.sync.shoppinglists.utils.ShoppingListTransformUtils)2 LocalizedString (io.sphere.sdk.models.LocalizedString)2 Reference (io.sphere.sdk.models.Reference)2 ShoppingListDraftBuilder (io.sphere.sdk.shoppinglists.ShoppingListDraftBuilder)2