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();
}
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);
}
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).");
}
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);
}
Aggregations