Search in sources :

Example 1 with CustomerSync

use of com.commercetools.sync.customers.CustomerSync in project commercetools-sync-java by commercetools.

the class CustomerSyncIT method setUpCustomerSync.

private void setUpCustomerSync() {
    errorMessages = new ArrayList<>();
    exceptions = new ArrayList<>();
    final CustomerSyncOptions customerSyncOptions = CustomerSyncOptionsBuilder.of(CTP_TARGET_CLIENT).errorCallback((exception, oldResource, newResource, actions) -> {
        errorMessages.add(exception.getMessage());
        exceptions.add(exception);
    }).build();
    customerSync = new CustomerSync(customerSyncOptions);
    referenceIdToKeyCache = new CaffeineReferenceIdToKeyCacheImpl();
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) CustomerTransformUtils(com.commercetools.sync.customers.utils.CustomerTransformUtils) CTP_SOURCE_CLIENT(com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_SOURCE_CLIENT) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AssertionsForStatistics.assertThat(com.commercetools.sync.commons.asserts.statistics.AssertionsForStatistics.assertThat) CustomerSyncStatistics(com.commercetools.sync.customers.helpers.CustomerSyncStatistics) Address(io.sphere.sdk.models.Address) CustomerITUtils.deleteCustomerSyncTestData(com.commercetools.sync.integration.commons.utils.CustomerITUtils.deleteCustomerSyncTestData) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) AfterAll(org.junit.jupiter.api.AfterAll) CustomerITUtils.createSampleCustomerJohnDoe(com.commercetools.sync.integration.commons.utils.CustomerITUtils.createSampleCustomerJohnDoe) CustomerQuery(io.sphere.sdk.customers.queries.CustomerQuery) ReferenceIdToKeyCache(com.commercetools.sync.commons.utils.ReferenceIdToKeyCache) Nonnull(javax.annotation.Nonnull) CountryCode(com.neovisionaries.i18n.CountryCode) CustomerITUtils.createSampleCustomerJaneDoe(com.commercetools.sync.integration.commons.utils.CustomerITUtils.createSampleCustomerJaneDoe) CaffeineReferenceIdToKeyCacheImpl(com.commercetools.sync.commons.utils.CaffeineReferenceIdToKeyCacheImpl) StoreITUtils.createStore(com.commercetools.sync.integration.commons.utils.StoreITUtils.createStore) CustomerDraftBuilder(io.sphere.sdk.customers.CustomerDraftBuilder) Store(io.sphere.sdk.stores.Store) CustomerSync(com.commercetools.sync.customers.CustomerSync) ITUtils.createCustomFieldsJsonMap(com.commercetools.sync.integration.commons.utils.ITUtils.createCustomFieldsJsonMap) Customer(io.sphere.sdk.customers.Customer) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) CustomerSyncOptionsBuilder(com.commercetools.sync.customers.CustomerSyncOptionsBuilder) CustomFieldsDraft(io.sphere.sdk.types.CustomFieldsDraft) List(java.util.List) CustomerSyncOptions(com.commercetools.sync.customers.CustomerSyncOptions) AssertionsForStatistics(com.commercetools.sync.commons.asserts.statistics.AssertionsForStatistics) CustomerDraft(io.sphere.sdk.customers.CustomerDraft) CTP_TARGET_CLIENT(com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT) ResourceIdentifier(io.sphere.sdk.models.ResourceIdentifier) CustomerSyncOptions(com.commercetools.sync.customers.CustomerSyncOptions) CustomerSync(com.commercetools.sync.customers.CustomerSync) CaffeineReferenceIdToKeyCacheImpl(com.commercetools.sync.commons.utils.CaffeineReferenceIdToKeyCacheImpl)

Example 2 with CustomerSync

use of com.commercetools.sync.customers.CustomerSync in project commercetools-project-sync by commercetools.

the class CustomerSyncer method of.

public static CustomerSyncer of(@Nonnull final SphereClient sourceClient, @Nonnull final SphereClient targetClient, @Nonnull final Clock clock) {
    final QuadConsumer<SyncException, Optional<CustomerDraft>, Optional<Customer>, List<UpdateAction<Customer>>> logErrorCallback = (exception, newResourceDraft, oldResource, updateActions) -> logErrorCallback(LOGGER, "customer", exception, oldResource, updateActions);
    final TriConsumer<SyncException, Optional<CustomerDraft>, Optional<Customer>> logWarningCallback = (exception, newResourceDraft, oldResource) -> logWarningCallback(LOGGER, "customer", exception, oldResource);
    final CustomerSyncOptions customerSyncOptions = CustomerSyncOptionsBuilder.of(targetClient).errorCallback(logErrorCallback).warningCallback(logWarningCallback).build();
    final CustomerSync customerSync = new CustomerSync(customerSyncOptions);
    final CustomObjectService customObjectService = new CustomObjectServiceImpl(targetClient);
    return new CustomerSyncer(customerSync, sourceClient, targetClient, customObjectService, clock);
}
Also used : SyncException(com.commercetools.sync.commons.exceptions.SyncException) LoggerFactory(org.slf4j.LoggerFactory) UpdateAction(io.sphere.sdk.commands.UpdateAction) QuadConsumer(com.commercetools.sync.commons.utils.QuadConsumer) CustomerSyncStatistics(com.commercetools.sync.customers.helpers.CustomerSyncStatistics) SyncUtils.logWarningCallback(com.commercetools.project.sync.util.SyncUtils.logWarningCallback) CustomerQuery(io.sphere.sdk.customers.queries.CustomerQuery) CustomerTransformUtils.toCustomerDrafts(com.commercetools.sync.customers.utils.CustomerTransformUtils.toCustomerDrafts) 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) CustomObjectService(com.commercetools.project.sync.service.CustomObjectService) CustomerSync(com.commercetools.sync.customers.CustomerSync) Customer(io.sphere.sdk.customers.Customer) CustomerSyncOptionsBuilder(com.commercetools.sync.customers.CustomerSyncOptionsBuilder) List(java.util.List) CustomerSyncOptions(com.commercetools.sync.customers.CustomerSyncOptions) 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) CustomerDraft(io.sphere.sdk.customers.CustomerDraft) CustomObjectService(com.commercetools.project.sync.service.CustomObjectService) Optional(java.util.Optional) CustomerSyncOptions(com.commercetools.sync.customers.CustomerSyncOptions) Customer(io.sphere.sdk.customers.Customer) CustomObjectServiceImpl(com.commercetools.project.sync.service.impl.CustomObjectServiceImpl) List(java.util.List) SyncException(com.commercetools.sync.commons.exceptions.SyncException) CustomerSync(com.commercetools.sync.customers.CustomerSync)

Example 3 with CustomerSync

use of com.commercetools.sync.customers.CustomerSync in project commercetools-sync-java by commercetools.

the class CustomerSyncIT method sync_WithNewCustomer_ShouldCreateCustomer.

@Test
void sync_WithNewCustomer_ShouldCreateCustomer() {
    final CustomerDraft newCustomerDraft = CustomerDraftBuilder.of(customerDraftJohnDoe).emailVerified(false).email("john-2@example.com").customerNumber("gold-2").key("customer-key-john-doe-2").build();
    final CustomerSyncOptions customerSyncOptions = CustomerSyncOptionsBuilder.of(CTP_TARGET_CLIENT).build();
    final CustomerSync customerSync = new CustomerSync(customerSyncOptions);
    final CustomerSyncStatistics customerSyncStatistics = customerSync.sync(singletonList(newCustomerDraft)).toCompletableFuture().join();
    assertThat(errorMessages).isEmpty();
    assertThat(warningMessages).isEmpty();
    assertThat(exceptions).isEmpty();
    assertThat(updateActionList).isEmpty();
    assertThat(customerSyncStatistics).hasValues(1, 1, 0, 0);
    assertThat(customerSyncStatistics.getReportMessage()).isEqualTo("Summary: 1 customers were processed in total (1 created, 0 updated and 0 failed to sync).");
}
Also used : CustomerSyncOptions(com.commercetools.sync.customers.CustomerSyncOptions) CustomerSync(com.commercetools.sync.customers.CustomerSync) CustomerSyncStatistics(com.commercetools.sync.customers.helpers.CustomerSyncStatistics) CustomerDraft(io.sphere.sdk.customers.CustomerDraft) Test(org.junit.jupiter.api.Test)

Example 4 with CustomerSync

use of com.commercetools.sync.customers.CustomerSync in project commercetools-sync-java by commercetools.

the class CustomerSyncIT method setUpCustomerSync.

private void setUpCustomerSync() {
    errorMessages = new ArrayList<>();
    exceptions = new ArrayList<>();
    warningMessages = new ArrayList<>();
    updateActionList = new ArrayList<>();
    CustomerSyncOptions customerSyncOptions = CustomerSyncOptionsBuilder.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();
    customerSync = new CustomerSync(customerSyncOptions);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Reference(io.sphere.sdk.models.Reference) AddBillingAddressId(io.sphere.sdk.customers.commands.updateactions.AddBillingAddressId) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) UpdateAction(io.sphere.sdk.commands.UpdateAction) SetStores(io.sphere.sdk.customers.commands.updateactions.SetStores) CustomerSyncStatistics(com.commercetools.sync.customers.helpers.CustomerSyncStatistics) Address(io.sphere.sdk.models.Address) Collections.singletonList(java.util.Collections.singletonList) AfterAll(org.junit.jupiter.api.AfterAll) CUSTOMER_NUMBER_EXISTS_WARNING(com.commercetools.sync.customers.utils.CustomerUpdateActionUtils.CUSTOMER_NUMBER_EXISTS_WARNING) CustomerITUtils.createSampleCustomerJohnDoe(com.commercetools.sync.integration.commons.utils.CustomerITUtils.createSampleCustomerJohnDoe) Collectors.toMap(java.util.stream.Collectors.toMap) SetMiddleName(io.sphere.sdk.customers.commands.updateactions.SetMiddleName) SetFirstName(io.sphere.sdk.customers.commands.updateactions.SetFirstName) Arrays.asList(java.util.Arrays.asList) SetDateOfBirth(io.sphere.sdk.customers.commands.updateactions.SetDateOfBirth) Locale(java.util.Locale) Map(java.util.Map) SetLocale(io.sphere.sdk.customers.commands.updateactions.SetLocale) ChangeEmail(io.sphere.sdk.customers.commands.updateactions.ChangeEmail) RemoveBillingAddressId(io.sphere.sdk.customers.commands.updateactions.RemoveBillingAddressId) Store(io.sphere.sdk.stores.Store) Customer(io.sphere.sdk.customers.Customer) String.format(java.lang.String.format) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) CustomerSyncOptionsBuilder(com.commercetools.sync.customers.CustomerSyncOptionsBuilder) List(java.util.List) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory) SetCustomerGroup(io.sphere.sdk.customers.commands.updateactions.SetCustomerGroup) SetVatId(io.sphere.sdk.customers.commands.updateactions.SetVatId) LocalDate(java.time.LocalDate) SetDefaultBillingAddress(io.sphere.sdk.customers.commands.updateactions.SetDefaultBillingAddress) SetCustomField(io.sphere.sdk.customers.commands.updateactions.SetCustomField) AddAddress(io.sphere.sdk.customers.commands.updateactions.AddAddress) CTP_TARGET_CLIENT(com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT) ResourceIdentifier(io.sphere.sdk.models.ResourceIdentifier) RemoveAddress(io.sphere.sdk.customers.commands.updateactions.RemoveAddress) SetTitle(io.sphere.sdk.customers.commands.updateactions.SetTitle) AssertionsForStatistics.assertThat(com.commercetools.sync.commons.asserts.statistics.AssertionsForStatistics.assertThat) CustomerITUtils.deleteCustomerSyncTestData(com.commercetools.sync.integration.commons.utils.CustomerITUtils.deleteCustomerSyncTestData) ArrayList(java.util.ArrayList) BOOLEAN_CUSTOM_FIELD_NAME(com.commercetools.sync.integration.commons.utils.ITUtils.BOOLEAN_CUSTOM_FIELD_NAME) AddShippingAddressId(io.sphere.sdk.customers.commands.updateactions.AddShippingAddressId) CountryCode(com.neovisionaries.i18n.CountryCode) CustomerGroup(io.sphere.sdk.customergroups.CustomerGroup) SetCompanyName(io.sphere.sdk.customers.commands.updateactions.SetCompanyName) SetSalutation(io.sphere.sdk.customers.commands.updateactions.SetSalutation) StoreITUtils.createStore(com.commercetools.sync.integration.commons.utils.StoreITUtils.createStore) CustomerDraftBuilder(io.sphere.sdk.customers.CustomerDraftBuilder) CustomerSync(com.commercetools.sync.customers.CustomerSync) ITUtils.createCustomFieldsJsonMap(com.commercetools.sync.integration.commons.utils.ITUtils.createCustomFieldsJsonMap) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) CustomerGroupITUtils.createCustomerGroup(com.commercetools.sync.integration.commons.utils.CustomerGroupITUtils.createCustomerGroup) CustomFieldsDraft(io.sphere.sdk.types.CustomFieldsDraft) CustomerSyncOptions(com.commercetools.sync.customers.CustomerSyncOptions) AddStore(io.sphere.sdk.customers.commands.updateactions.AddStore) LOCALISED_STRING_CUSTOM_FIELD_NAME(com.commercetools.sync.integration.commons.utils.ITUtils.LOCALISED_STRING_CUSTOM_FIELD_NAME) CustomerDraft(io.sphere.sdk.customers.CustomerDraft) CustomerSyncOptions(com.commercetools.sync.customers.CustomerSyncOptions) CustomerSync(com.commercetools.sync.customers.CustomerSync)

Aggregations

CustomerSync (com.commercetools.sync.customers.CustomerSync)4 CustomerSyncOptions (com.commercetools.sync.customers.CustomerSyncOptions)4 CustomerSyncStatistics (com.commercetools.sync.customers.helpers.CustomerSyncStatistics)4 CustomerDraft (io.sphere.sdk.customers.CustomerDraft)4 CustomerSyncOptionsBuilder (com.commercetools.sync.customers.CustomerSyncOptionsBuilder)3 Customer (io.sphere.sdk.customers.Customer)3 List (java.util.List)3 Test (org.junit.jupiter.api.Test)3 AssertionsForStatistics.assertThat (com.commercetools.sync.commons.asserts.statistics.AssertionsForStatistics.assertThat)2 CustomerITUtils.createSampleCustomerJohnDoe (com.commercetools.sync.integration.commons.utils.CustomerITUtils.createSampleCustomerJohnDoe)2 CustomerITUtils.deleteCustomerSyncTestData (com.commercetools.sync.integration.commons.utils.CustomerITUtils.deleteCustomerSyncTestData)2 ITUtils.createCustomFieldsJsonMap (com.commercetools.sync.integration.commons.utils.ITUtils.createCustomFieldsJsonMap)2 CTP_TARGET_CLIENT (com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT)2 StoreITUtils.createStore (com.commercetools.sync.integration.commons.utils.StoreITUtils.createStore)2 CountryCode (com.neovisionaries.i18n.CountryCode)2 UpdateAction (io.sphere.sdk.commands.UpdateAction)2 CustomerDraftBuilder (io.sphere.sdk.customers.CustomerDraftBuilder)2 Syncer (com.commercetools.project.sync.Syncer)1 CustomObjectService (com.commercetools.project.sync.service.CustomObjectService)1 CustomObjectServiceImpl (com.commercetools.project.sync.service.impl.CustomObjectServiceImpl)1