use of com.commercetools.sync.commons.utils.QuadConsumer 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);
}
use of com.commercetools.sync.commons.utils.QuadConsumer in project commercetools-project-sync by commercetools.
the class CartDiscountSyncer method of.
@Nonnull
public static CartDiscountSyncer of(@Nonnull final SphereClient sourceClient, @Nonnull final SphereClient targetClient, @Nonnull final Clock clock) {
final QuadConsumer<SyncException, Optional<CartDiscountDraft>, Optional<CartDiscount>, List<UpdateAction<CartDiscount>>> logErrorCallback = (exception, newResourceDraft, oldResource, updateActions) -> logErrorCallback(LOGGER, "cart discount", exception, oldResource, updateActions);
final TriConsumer<SyncException, Optional<CartDiscountDraft>, Optional<CartDiscount>> logWarningCallback = (exception, newResourceDraft, oldResource) -> logWarningCallback(LOGGER, "cart discount", exception, oldResource);
final CartDiscountSyncOptions syncOptions = CartDiscountSyncOptionsBuilder.of(targetClient).errorCallback(logErrorCallback).warningCallback(logWarningCallback).build();
final CartDiscountSync cartDiscountSync = new CartDiscountSync(syncOptions);
final CustomObjectService customObjectService = new CustomObjectServiceImpl(targetClient);
return new CartDiscountSyncer(cartDiscountSync, sourceClient, targetClient, customObjectService, clock);
}
use of com.commercetools.sync.commons.utils.QuadConsumer in project commercetools-sync-java by commercetools.
the class InventorySyncIT method sync_WithCustomErrorCallback_ShouldExecuteCallbackOnError.
@Test
void sync_WithCustomErrorCallback_ShouldExecuteCallbackOnError() {
// Fetch new inventories from source project. Convert them to drafts.
final List<InventoryEntry> inventoryEntries = CTP_SOURCE_CLIENT.execute(InventoryEntryQuery.of().withExpansionPaths(InventoryEntryExpansionModel::supplyChannel).plusExpansionPaths(ExpansionPath.of("custom.type"))).toCompletableFuture().join().getResults();
final List<InventoryEntryDraft> newInventories = InventoryTransformUtils.toInventoryEntryDrafts(CTP_SOURCE_CLIENT, REFERENCE_ID_TO_KEY_CACHE, inventoryEntries).join();
// Prepare sync options and perform sync of draft to target project.
final AtomicInteger invocationCounter = new AtomicInteger(0);
QuadConsumer<SyncException, Optional<InventoryEntryDraft>, Optional<InventoryEntry>, List<UpdateAction<InventoryEntry>>> countingErrorCallback = (exception, newResource, oldResource, updateActions) -> invocationCounter.incrementAndGet();
final InventorySyncOptions inventorySyncOptions = InventorySyncOptionsBuilder.of(CTP_TARGET_CLIENT).errorCallback(countingErrorCallback).ensureChannels(false).build();
final InventorySync inventorySync = new InventorySync(inventorySyncOptions);
final InventorySyncStatistics inventorySyncStatistics = inventorySync.sync(newInventories).toCompletableFuture().join();
assertThat(inventorySyncStatistics).hasValues(3, 0, 1, 1);
assertThat(invocationCounter.get()).isEqualTo(1);
}
use of com.commercetools.sync.commons.utils.QuadConsumer 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);
}
use of com.commercetools.sync.commons.utils.QuadConsumer in project commercetools-project-sync by commercetools.
the class ProductTypeSyncer method of.
@Nonnull
public static ProductTypeSyncer of(@Nonnull final SphereClient sourceClient, @Nonnull final SphereClient targetClient, @Nonnull final Clock clock) {
final QuadConsumer<SyncException, Optional<ProductTypeDraft>, Optional<ProductType>, List<UpdateAction<ProductType>>> logErrorCallback = (exception, newResourceDraft, oldResource, updateActions) -> logErrorCallback(LOGGER, "product type", exception, oldResource, updateActions);
final TriConsumer<SyncException, Optional<ProductTypeDraft>, Optional<ProductType>> logWarningCallback = (exception, newResourceDraft, oldResource) -> logWarningCallback(LOGGER, "product type", exception, oldResource);
final ProductTypeSyncOptions syncOptions = ProductTypeSyncOptionsBuilder.of(targetClient).errorCallback(logErrorCallback).warningCallback(logWarningCallback).build();
final ProductTypeSync productTypeSync = new ProductTypeSync(syncOptions);
final CustomObjectService customObjectService = new CustomObjectServiceImpl(targetClient);
return new ProductTypeSyncer(productTypeSync, sourceClient, targetClient, customObjectService, clock);
}
Aggregations