use of com.commercetools.sync.commons.utils.TriConsumer 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.TriConsumer 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.TriConsumer in project commercetools-sync-java by commercetools.
the class CategoryUpdateActionUtilsTest method buildChangeOrderHintUpdateAction_WithNullValues_ShouldNotBuildUpdateActionAndCallCallback.
@Test
void buildChangeOrderHintUpdateAction_WithNullValues_ShouldNotBuildUpdateActionAndCallCallback() {
when(MOCK_OLD_CATEGORY.getId()).thenReturn("oldCatId");
final CategoryDraft newCategory = mock(CategoryDraft.class);
when(newCategory.getOrderHint()).thenReturn(null);
final ArrayList<Object> callBackResponse = new ArrayList<>();
final TriConsumer<SyncException, Optional<CategoryDraft>, Optional<Category>> updateActionWarningCallBack = (exception, newResource, oldResource) -> callBackResponse.add(exception.getMessage());
final CategorySyncOptions categorySyncOptions = CategorySyncOptionsBuilder.of(CTP_CLIENT).warningCallback(updateActionWarningCallBack).build();
final Optional<UpdateAction<Category>> changeOrderHintUpdateAction = buildChangeOrderHintUpdateAction(MOCK_OLD_CATEGORY, newCategory, categorySyncOptions);
assertThat(changeOrderHintUpdateAction).isNotNull();
assertThat(changeOrderHintUpdateAction).isNotPresent();
assertThat(callBackResponse).hasSize(1);
assertThat(callBackResponse.get(0)).isEqualTo("Cannot unset 'orderHint' field of category with id 'oldCatId'.");
}
use of com.commercetools.sync.commons.utils.TriConsumer in project commercetools-sync-java by commercetools.
the class CategoryUpdateActionUtilsTest method buildChangeParentUpdateAction_WithBothNullValues_ShouldNotBuildUpdateActionAndNotCallCallback.
@Test
void buildChangeParentUpdateAction_WithBothNullValues_ShouldNotBuildUpdateActionAndNotCallCallback() {
when(MOCK_OLD_CATEGORY.getId()).thenReturn("oldCatId");
when(MOCK_OLD_CATEGORY.getParent()).thenReturn(null);
final CategoryDraft newCategory = mock(CategoryDraft.class);
when(newCategory.getParent()).thenReturn(null);
final ArrayList<Object> callBackResponse = new ArrayList<>();
final TriConsumer<SyncException, Optional<CategoryDraft>, Optional<Category>> updateActionWarningCallBack = (exception, newResource, oldResource) -> callBackResponse.add(exception.getMessage());
final CategorySyncOptions categorySyncOptions = CategorySyncOptionsBuilder.of(CTP_CLIENT).warningCallback(updateActionWarningCallBack).build();
final Optional<UpdateAction<Category>> changeParentUpdateAction = buildChangeParentUpdateAction(MOCK_OLD_CATEGORY, newCategory, categorySyncOptions);
assertThat(changeParentUpdateAction).isNotNull();
assertThat(changeParentUpdateAction).isNotPresent();
assertThat(callBackResponse).isEmpty();
}
use of com.commercetools.sync.commons.utils.TriConsumer in project commercetools-sync-java by commercetools.
the class CategoryUpdateActionUtilsTest method buildChangeOrderHintUpdateAction_WithBothNullValues_ShouldNotBuildUpdateActionAndNotCallCallback.
@Test
void buildChangeOrderHintUpdateAction_WithBothNullValues_ShouldNotBuildUpdateActionAndNotCallCallback() {
when(MOCK_OLD_CATEGORY.getId()).thenReturn("oldCatId");
when(MOCK_OLD_CATEGORY.getOrderHint()).thenReturn(null);
final CategoryDraft newCategory = mock(CategoryDraft.class);
when(newCategory.getOrderHint()).thenReturn(null);
final ArrayList<Object> callBackResponse = new ArrayList<>();
final TriConsumer<SyncException, Optional<CategoryDraft>, Optional<Category>> updateActionWarningCallBack = (exception, newResource, oldResource) -> callBackResponse.add(exception.getMessage());
final CategorySyncOptions categorySyncOptions = CategorySyncOptionsBuilder.of(CTP_CLIENT).warningCallback(updateActionWarningCallBack).build();
final Optional<UpdateAction<Category>> changeOrderHintUpdateAction = buildChangeOrderHintUpdateAction(MOCK_OLD_CATEGORY, newCategory, categorySyncOptions);
assertThat(changeOrderHintUpdateAction).isNotNull();
assertThat(changeOrderHintUpdateAction).isNotPresent();
assertThat(callBackResponse).isEmpty();
}
Aggregations