Class InventorySync


  • public final class InventorySync
    extends BaseSync<com.commercetools.api.models.inventory.InventoryEntry,​com.commercetools.api.models.inventory.InventoryEntryDraft,​com.commercetools.api.models.inventory.InventoryEntryUpdateAction,​InventorySyncStatistics,​InventorySyncOptions>
    Default implementation of inventories sync process.
    • Constructor Detail

      • InventorySync

        public InventorySync​(@Nonnull
                             InventorySyncOptions syncOptions)
        Takes a InventorySyncOptions instance to instantiate a new InventorySync instance that could be used to sync inventory drafts with the given inventory entries in the CTP project specified in the injected InventorySyncOptions instance.
        Parameters:
        syncOptions - the container of all the options of the sync process including the CTP project client and/or configuration and other sync-specific options.
    • Method Detail

      • process

        @Nonnull
        protected java.util.concurrent.CompletionStage<InventorySyncStatistics> process​(@Nonnull
                                                                                        java.util.List<com.commercetools.api.models.inventory.InventoryEntryDraft> inventoryEntryDrafts)
        Iterates through the whole inventories 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.inventory.InventoryEntry,​com.commercetools.api.models.inventory.InventoryEntryDraft,​com.commercetools.api.models.inventory.InventoryEntryUpdateAction,​InventorySyncStatistics,​InventorySyncOptions>
        Parameters:
        inventoryEntryDrafts - List of InventoryEntryDraft resources that would be synced into CTP project.
        Returns:
        CompletionStage with InventorySyncStatistics holding statistics of all sync processes performed by this sync instance
      • processBatch

        protected java.util.concurrent.CompletionStage<InventorySyncStatistics> processBatch​(@Nonnull
                                                                                             java.util.List<com.commercetools.api.models.inventory.InventoryEntryDraft> batch)
        Fetches existing InventoryEntry objects from CTP project that correspond to passed batchOfDrafts. Having existing inventory entries fetched, batchOfDrafts is compared and synced with fetched objects by syncBatch(Set, Set) function. When fetching existing inventory entries results in an empty optional then batchOfDrafts isn't processed.
        Specified by:
        processBatch in class BaseSync<com.commercetools.api.models.inventory.InventoryEntry,​com.commercetools.api.models.inventory.InventoryEntryDraft,​com.commercetools.api.models.inventory.InventoryEntryUpdateAction,​InventorySyncStatistics,​InventorySyncOptions>
        Parameters:
        batch - batch of drafts that need to be synced
        Returns:
        CompletionStage of Void that indicates method progress.