Search in sources :

Example 1 with IDENTIFIER_NOT_PRESENT

use of com.commercetools.project.sync.util.SyncUtils.IDENTIFIER_NOT_PRESENT 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 IDENTIFIER_NOT_PRESENT

use of com.commercetools.project.sync.util.SyncUtils.IDENTIFIER_NOT_PRESENT in project commercetools-project-sync by commercetools.

the class ProductSyncer method of.

@Nonnull
public static ProductSyncer of(@Nonnull final SphereClient sourceClient, @Nonnull final SphereClient targetClient, @Nonnull final Clock clock, @Nullable final ProductSyncCustomRequest productSyncCustomRequest) {
    final QuadConsumer<SyncException, Optional<ProductDraft>, Optional<ProductProjection>, List<UpdateAction<Product>>> logErrorCallback = (exception, newResourceDraft, oldResource, updateActions) -> {
        final String resourceKey = oldResource.map(WithKey::getKey).orElse(IDENTIFIER_NOT_PRESENT);
        logErrorCallback(LOGGER, "product", exception, resourceKey, updateActions);
    };
    final TriConsumer<SyncException, Optional<ProductDraft>, Optional<ProductProjection>> logWarningCallback = (exception, newResourceDraft, oldResource) -> logWarningCallback(LOGGER, "product", exception, oldResource);
    final ProductSyncOptions syncOptions = ProductSyncOptionsBuilder.of(targetClient).errorCallback(logErrorCallback).warningCallback(logWarningCallback).build();
    final ProductSync productSync = new ProductSync(syncOptions);
    final CustomObjectService customObjectService = new CustomObjectServiceImpl(targetClient);
    return new ProductSyncer(productSync, sourceClient, targetClient, customObjectService, clock, productSyncCustomRequest);
}
Also used : ProductTransformUtils.toProductDrafts(com.commercetools.sync.products.utils.ProductTransformUtils.toProductDrafts) ProductProjectionQuery(io.sphere.sdk.products.queries.ProductProjectionQuery) SyncException(com.commercetools.sync.commons.exceptions.SyncException) LoggerFactory(org.slf4j.LoggerFactory) UpdateAction(io.sphere.sdk.commands.UpdateAction) QuadConsumer(com.commercetools.sync.commons.utils.QuadConsumer) SyncUtils.logWarningCallback(com.commercetools.project.sync.util.SyncUtils.logWarningCallback) ProductSync(com.commercetools.sync.products.ProductSync) SphereClient(io.sphere.sdk.client.SphereClient) TriConsumer(com.commercetools.sync.commons.utils.TriConsumer) ProductDraft(io.sphere.sdk.products.ProductDraft) ProductProjection(io.sphere.sdk.products.ProductProjection) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) ProductSyncCustomRequest(com.commercetools.project.sync.model.ProductSyncCustomRequest) SyncUtils.logErrorCallback(com.commercetools.project.sync.util.SyncUtils.logErrorCallback) WithKey(io.sphere.sdk.models.WithKey) Logger(org.slf4j.Logger) QueryPredicate(io.sphere.sdk.queries.QueryPredicate) IDENTIFIER_NOT_PRESENT(com.commercetools.project.sync.util.SyncUtils.IDENTIFIER_NOT_PRESENT) CustomObjectService(com.commercetools.project.sync.service.CustomObjectService) CompletionException(java.util.concurrent.CompletionException) Product(io.sphere.sdk.products.Product) List(java.util.List) ProductSyncStatistics(com.commercetools.sync.products.helpers.ProductSyncStatistics) CompletionStage(java.util.concurrent.CompletionStage) ProductSyncOptionsBuilder(com.commercetools.sync.products.ProductSyncOptionsBuilder) Syncer(com.commercetools.project.sync.Syncer) Clock(java.time.Clock) Optional(java.util.Optional) CustomObjectServiceImpl(com.commercetools.project.sync.service.impl.CustomObjectServiceImpl) Collections(java.util.Collections) ProductSyncOptions(com.commercetools.sync.products.ProductSyncOptions) Optional(java.util.Optional) WithKey(io.sphere.sdk.models.WithKey) Product(io.sphere.sdk.products.Product) ProductSync(com.commercetools.sync.products.ProductSync) SyncException(com.commercetools.sync.commons.exceptions.SyncException) CustomObjectService(com.commercetools.project.sync.service.CustomObjectService) CustomObjectServiceImpl(com.commercetools.project.sync.service.impl.CustomObjectServiceImpl) List(java.util.List) ProductSyncOptions(com.commercetools.sync.products.ProductSyncOptions) Nonnull(javax.annotation.Nonnull)

Example 3 with IDENTIFIER_NOT_PRESENT

use of com.commercetools.project.sync.util.SyncUtils.IDENTIFIER_NOT_PRESENT in project commercetools-project-sync by commercetools.

the class InventoryEntrySyncer method of.

public static InventoryEntrySyncer of(@Nonnull final SphereClient sourceClient, @Nonnull final SphereClient targetClient, @Nonnull final Clock clock) {
    final QuadConsumer<SyncException, Optional<InventoryEntryDraft>, Optional<InventoryEntry>, List<UpdateAction<InventoryEntry>>> logErrorCallback = (exception, newResourceDraft, oldResource, updateActions) -> logErrorCallback(LOGGER, "inventory entry", exception, oldResource.map(InventoryEntry::getSku).orElse(IDENTIFIER_NOT_PRESENT), updateActions);
    final TriConsumer<SyncException, Optional<InventoryEntryDraft>, Optional<InventoryEntry>> logWarningCallback = (exception, newResourceDraft, oldResource) -> logWarningCallback(LOGGER, "inventory entry", exception, oldResource.map(InventoryEntry::getSku).orElse(IDENTIFIER_NOT_PRESENT));
    final InventorySyncOptions syncOptions = InventorySyncOptionsBuilder.of(targetClient).errorCallback(logErrorCallback).warningCallback(logWarningCallback).build();
    final InventorySync inventorySync = new InventorySync(syncOptions);
    final CustomObjectService customObjectService = new CustomObjectServiceImpl(targetClient);
    return new InventoryEntrySyncer(inventorySync, sourceClient, targetClient, customObjectService, clock);
}
Also used : SyncException(com.commercetools.sync.commons.exceptions.SyncException) InventoryEntryDraft(io.sphere.sdk.inventory.InventoryEntryDraft) LoggerFactory(org.slf4j.LoggerFactory) InventorySyncOptionsBuilder(com.commercetools.sync.inventories.InventorySyncOptionsBuilder) UpdateAction(io.sphere.sdk.commands.UpdateAction) QuadConsumer(com.commercetools.sync.commons.utils.QuadConsumer) InventoryTransformUtils.toInventoryEntryDrafts(com.commercetools.sync.inventories.utils.InventoryTransformUtils.toInventoryEntryDrafts) SyncUtils.logWarningCallback(com.commercetools.project.sync.util.SyncUtils.logWarningCallback) SphereClient(io.sphere.sdk.client.SphereClient) TriConsumer(com.commercetools.sync.commons.utils.TriConsumer) InventoryEntryQuery(io.sphere.sdk.inventory.queries.InventoryEntryQuery) Nonnull(javax.annotation.Nonnull) SyncUtils.logErrorCallback(com.commercetools.project.sync.util.SyncUtils.logErrorCallback) Logger(org.slf4j.Logger) IDENTIFIER_NOT_PRESENT(com.commercetools.project.sync.util.SyncUtils.IDENTIFIER_NOT_PRESENT) CustomObjectService(com.commercetools.project.sync.service.CustomObjectService) InventoryEntry(io.sphere.sdk.inventory.InventoryEntry) InventorySync(com.commercetools.sync.inventories.InventorySync) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) InventorySyncOptions(com.commercetools.sync.inventories.InventorySyncOptions) Syncer(com.commercetools.project.sync.Syncer) Clock(java.time.Clock) Optional(java.util.Optional) CustomObjectServiceImpl(com.commercetools.project.sync.service.impl.CustomObjectServiceImpl) InventorySyncStatistics(com.commercetools.sync.inventories.helpers.InventorySyncStatistics) CustomObjectService(com.commercetools.project.sync.service.CustomObjectService) Optional(java.util.Optional) InventorySync(com.commercetools.sync.inventories.InventorySync) CustomObjectServiceImpl(com.commercetools.project.sync.service.impl.CustomObjectServiceImpl) List(java.util.List) InventoryEntry(io.sphere.sdk.inventory.InventoryEntry) SyncException(com.commercetools.sync.commons.exceptions.SyncException) InventorySyncOptions(com.commercetools.sync.inventories.InventorySyncOptions)

Aggregations

Syncer (com.commercetools.project.sync.Syncer)3 CustomObjectService (com.commercetools.project.sync.service.CustomObjectService)3 CustomObjectServiceImpl (com.commercetools.project.sync.service.impl.CustomObjectServiceImpl)3 IDENTIFIER_NOT_PRESENT (com.commercetools.project.sync.util.SyncUtils.IDENTIFIER_NOT_PRESENT)3 SyncUtils.logErrorCallback (com.commercetools.project.sync.util.SyncUtils.logErrorCallback)3 SyncUtils.logWarningCallback (com.commercetools.project.sync.util.SyncUtils.logWarningCallback)3 SyncException (com.commercetools.sync.commons.exceptions.SyncException)3 QuadConsumer (com.commercetools.sync.commons.utils.QuadConsumer)3 TriConsumer (com.commercetools.sync.commons.utils.TriConsumer)3 SphereClient (io.sphere.sdk.client.SphereClient)3 UpdateAction (io.sphere.sdk.commands.UpdateAction)3 Clock (java.time.Clock)3 List (java.util.List)3 Optional (java.util.Optional)3 CompletionStage (java.util.concurrent.CompletionStage)3 Nonnull (javax.annotation.Nonnull)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 ProductSyncCustomRequest (com.commercetools.project.sync.model.ProductSyncCustomRequest)1 InventorySync (com.commercetools.sync.inventories.InventorySync)1