Class CustomerSync


  • public class CustomerSync
    extends BaseSync<com.commercetools.api.models.customer.Customer,​com.commercetools.api.models.customer.CustomerDraft,​com.commercetools.api.models.customer.CustomerUpdateAction,​CustomerSyncStatistics,​CustomerSyncOptions>
    This class syncs customer drafts with the corresponding customers in the CTP project.
    • Constructor Detail

      • CustomerSync

        public CustomerSync​(@Nonnull
                            CustomerSyncOptions customerSyncOptions)
        Takes a CustomerSyncOptions to instantiate a new CustomerSync instance that could be used to sync customer drafts in the CTP project specified in the injected CustomerSync instance.
        Parameters:
        customerSyncOptions - the container of all the options of the sync process including the CTP project client and/or configuration and other sync-specific options.
      • CustomerSync

        protected CustomerSync​(@Nonnull
                               CustomerSyncOptions customerSyncOptions,
                               @Nonnull
                               CustomerService customerService,
                               @Nonnull
                               TypeService typeService,
                               @Nonnull
                               CustomerGroupService customerGroupService)
        Takes a CustomerSyncOptions and service instances to instantiate a new CustomerSync instance that could be used to sync customer drafts in the CTP project specified in the injected CustomerSyncOptions instance.

        NOTE: This constructor is mainly to be used for tests where the services can be mocked and passed to.

        Parameters:
        customerSyncOptions - the container of all the options of the sync process including the CTP project client and/or configuration and other sync-specific options.
        customerService - the customer service which is responsible for fetching/caching the Customers from the CTP project.
        typeService - the type service which is responsible for fetching/caching the Types from the CTP project.
        customerGroupService - the customer group service which is responsible for fetching/caching the CustomerGroups from the CTP project.
    • Method Detail

      • process

        protected java.util.concurrent.CompletionStage<CustomerSyncStatistics> process​(@Nonnull
                                                                                       java.util.List<com.commercetools.api.models.customer.CustomerDraft> customerDrafts)
        Iterates through the whole customerDrafts list and accumulates its valid drafts to batches. Every batch is then processed by processBatch(List).

        Inherited doc: Given a list of resource (e.g. categories, products, etc..) drafts. This method compares each new resource in this list with it's corresponding old resource in a given CTP project, and in turn it either issues update actions on the existing resource if it exists or create it if it doesn't.

        Specified by:
        process in class BaseSync<com.commercetools.api.models.customer.Customer,​com.commercetools.api.models.customer.CustomerDraft,​com.commercetools.api.models.customer.CustomerUpdateAction,​CustomerSyncStatistics,​CustomerSyncOptions>
        Parameters:
        customerDrafts - List of CustomerDraft's that would be synced into CTP project.
        Returns:
        CompletionStage with CustomerSyncStatistics holding statistics of all sync processes performed by this sync instance.
      • processBatch

        protected java.util.concurrent.CompletionStage<CustomerSyncStatistics> processBatch​(@Nonnull
                                                                                            java.util.List<com.commercetools.api.models.customer.CustomerDraft> batch)
        Specified by:
        processBatch in class BaseSync<com.commercetools.api.models.customer.Customer,​com.commercetools.api.models.customer.CustomerDraft,​com.commercetools.api.models.customer.CustomerUpdateAction,​CustomerSyncStatistics,​CustomerSyncOptions>